Solved

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

Posted on 2007-03-27
8
192 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:jsound
  • 4
  • 2
  • 2
8 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 18802367
>The problem I am having is that the service was installed with a local user account.
did you configure the service to interact with the desktop?

>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.)
you should ensure that you have proper error handling in the application. when started from a service, applications might work differently...
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 200 total points
ID: 18802374
So, do you know if it's permissions or the code?

What if you alter the above slightly to read:

myProcesses = Process.GetProcessesByName("myapp")
If myProcesses.Length = 0 Then
  Dim p As New Process
  With p.StartInfo
      .FileName="myapp.exe"
      .WorkingDirectory = "c:\exefolder"
  End With
  p.Start()
End If
0
 

Author Comment

by:jsound
ID: 18802516
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
0
 

Author Comment

by:jsound
ID: 18802974
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
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18803056
nothing except what I suggested already: logging code to see what exception is raised (ie your application does NOT handle exceptions properly at startup)
0
 

Author Comment

by:jsound
ID: 18803931
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
0
 

Author Comment

by:jsound
ID: 18804149
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18804164
Glad to assist - thanx! :^)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now