Link to home
Start Free TrialLog in
Avatar of jsound
jsound

asked on

VB.NET 2005: Service to check if application is running

I have written a Windows service that periodically checks to see if an instance of an application is running and if not, it starts the application.

The problem I am having is that the service was installed with a local user account. It looks like the service goes through the motion of checking for the instance, but I never see the application on screen and instead hear a Windows error popup sound (and really don't see an error dialog on the screen either.)

What could be the issue?

Here is my code:

        myProcesses = Process.GetProcessesByName("myapp")

        If myProcesses.Length = 0 Then
            Dim p As ProcessStartInfo = New ProcessStartInfo("myapp.exe")
            p.WorkingDirectory = "c:\exefolder"
            Dim process As Process = New Process
            process.Start(p)
        End If
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jsound
jsound

ASKER

AngelIII, I think that may be the problem.

Is there an easy way (other than hacking the registry) to set this up? There is nothing in the ServiceInstaller that will let me do that.

JB
Avatar of jsound

ASKER

Alright, I went into the registry to set the Type of the service to 256, which should specify that the service should interact with the desktop. However, I'm still getting the audible error (again, no error display) and the app won't end up starting up, only a quick blip in the Task Manager as a process.

Any other suggestions?

JB
nothing except what I suggested already: logging code to see what exception is raised (ie your application does NOT handle exceptions properly at startup)
Avatar of jsound

ASKER

OK, I checked about everything that I could. I added error handling to the service, attached the debugger to the service and didn't really get any exceptions thrown in the service itself. As far as the service is concerned, everything looks goog. The process.Start(p) fires up just fine and returns no error. However, the application still doesn't get started.

Here is a little more information what I am actually trying to accomplish:

I think there may be a fundamental question around whether the service really needs to be interactive or not. The service itself DOES NOT interact with the user. It is the application that the service is to start that is to interact with the user.

This application is just like any other UI app (like Notepad or others). All the service is to do is to check and see whether the app is running and if not, to start it up.

Some may think that this is bordering on writing a malicious application. :-)  Believe me, it is not. This is for a kiosk application that we need to make sure runs all the time. If it is not, then it is supposed to be started by the service.

In the light of these additional details, any suggestions on how to proceed?

JB
Avatar of jsound

ASKER

Well, I got it going. There was nothing wrong with the code (yours or mine), nor was there anything wrong with installing the service. It seems that there is some funky behavior going on with setting the 'Allow service to interact with desktop' either in code or through the registry (at least without a reboot of the system, which I did not test.)

Turns out that if I manually change that setting for the service in the Services Management Console, everything behaves as expected.

So points to angelIII for the tips and points to sirbounty for chiming in!

Thanks everybody,

JB
Glad to assist - thanx! :^)