NEWS

Tuesday, September 4, 2012

Calling an exe from Windows Service


Some times we may need to call an exe from our windows service program. The following code can be used to call an exe from an appication. The sample code is for VB.NET applications. Here the calculator (calc.exe) is called.

Dim startInfo As System.Diagnostics.ProcessStartInfo

Dim pStart As New System.Diagnostics.Process
'Start the process
startInfo = New System.Diagnostics.ProcessStartInfo("calc.exe")
pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()
pStart.Close()
Here
pStart.WaitForExit() makes your application wait till the called exe is closed.
pStart.Close() will free all the resources that are associated with this component.
This will work if you are using a windows Application. But in a windows service this will not work straight, you need to change some setting for the windows service. A service won't be able to show the GUI of an application, so if the application you are calling has any GUI you won't be able to see it. But the process will get kicked off and you can see the evidence in TaskManager. But we can enable the service to popup the UI by enabling this settings.
Allow Services to interact with desktop
  1. Start -> Run -> Services.msc
  2. Locate the services which you have created
  3. Right click and select properties.
  4. Select "Log On" tab on the top of the screen
  5. Select "Allow Services to interact with desktop" check box.
  6. Click on "Apply" and start the services.
If you want to kill an application during Windows Service Stop, try the following code
Dim myProcess As Process
Dim myProcesses As Process() = Process.GetProcessesByName("calc")
For Each myProcess In myProcesses
myProcess.Kill()
Next

Monday, August 13, 2012

Windows 7 trick: unlock the secret God Mode folder

So, what exactly is God Mode in Windows 7? 

Well, for starters, it's not really a mode. And it's nothing you need to be a deity to pull off, either.

Rather, it's a folder packed with shortcuts to just about every settings change and administrative function in Windows 7. Everything you'll find in the Action Center, Backup and Restore, Autorun, Desktop Gadgets, Devices and Printers -- it's all there. All dumped in one central location for easy access.

No, this trick doesn't involve entering IDDQD in the run box - but it's just about that simple. Here's the magic, as provided by the guys at Windows 7 Themes:
  • Create a new folder anywhere (I set mine up in d:\)
  • Rename the folder and paste in the following text: GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
That's it! You've now got your new, somewhat handy folder. Why somewhat handy? Well, because you can already access everything in there by typing a few letters into the search box on your start menu. 

Friday, July 20, 2012

Free E-book: Time-Saving VS11 and ASP.NET 4.5 Features You Shouldn’t Miss