Solved

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

Posted on 2007-03-27
8
195 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 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