Solved

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

Posted on 2007-03-27
8
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 143

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 143

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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