Solved

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

Posted on 2007-03-27
8
199 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 44
how to make search between pages 17 60
VB.net Filesystem watcher not working 5 58
.NET Redemption/Outlook Examples 3 35
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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