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.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


  1. These are fundamentally brief phrase loans that do deliver you
    meet your fiscal difficulties inside a preferred specific time period.
    Considering time limitations these loans are specifically designed above an obligation 100 % free platform. As such, these are kept completely zero cost from credential checksums. Difficulties such as defaults, arrears, bankruptcy, CCJs and even IVAs are not viewed as right here. Further, there are also no collaterals linked with these loans. There is minimal paper function expected on the portion of borrower. There are also no hidden or added documentation or faxing necessary right here. Applying for these loans is also really hassle-free. People merely need filling an on line type and as soon as this gets authorized cash is received within 24 hours time frame. These loans are typically supplied under hassle-free terms and situations. The basic simple applicant criteria here is that they must be a UK resident and of 18 years of age.
    Here is my weblog ...

  2. Hurrah, that's what I was exploring for, what a information! existing here at this webpage, thanks admin of this web site.

    Also visit my page :: nickelodeon games avatar
    Also see my page - youtube converter

  3. When you're happy with your game, why not share it with the world. If they throw a big pre-flop raise and look at this way, is quite clear, in the last hour flop continuation bet (cbets) 3 then. He then becomes more superstitious and does not realize that it was his subconscious that made him lose the game.

    My weblog;
    Also see my website -

  4. I needed to thank you for this very good read!! I definitely loved every bit of it.
    I've got you book marked to check out new things you post…

    my blog post - paleo diät

  5. Great post. I was checking constantly this blog
    and I am impressed! Extremely helpful information specifically
    the last part :) I care for such info a lot. I was seeking this certain information for a very long
    time. Thank you and good luck.

    Stop by my web page ::

  6. Hello! I'm at work surfing around your blog from my new iphone 3gs! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the superb work!

    Here is my website: Dayton Movers