inzo21 Posted June 1, 2004 Posted June 1, 2004 Hey all, I'm trying to detect the presence of a specific windows service by name and I am not able to do so. Here is the code I'm using: btsched = New ServiceController("theservicename", ".") Try MsgBox("The theservicename is" & btsched.Status.ToString, 64, "Service Monitor") Catch ex As Exception MsgBox("The theservicename must be installed prior to starting BackTrack Monitor", MsgBoxStyle.Critical, "Service Monitor") Application.Exit() End Try I couldn't find a servicecontroller .exists method so I am testing the service in this try statement. The issue I have is that the application (which is a system tray application) does not exit upon the try clause exception. any ideas? thanx in advance, inzo Quote he who forgets will be destined to remember... (E.Vedder)
Administrators PlausiblyDamp Posted June 1, 2004 Administrators Posted June 1, 2004 You could call the NotifyIcon's Dispose method in the catch block Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
inzo21 Posted June 1, 2004 Author Posted June 1, 2004 Got It! Thanks PDamp. That didn't work, however. The runtime had a problem calling the dispose method of the form class directly - and I didn't want to marshal the reference or anything. Thus, I came up with the following and added it to the exception catch: Dim pholder As Process = Process.GetCurrentProcess pholder.Kill() it kills the process of the current executing thread - just what I needed. I was attempting to terminate the application - which worked - but not the process that got started as a result of it. for those reading, you'll need to import system.serviceprocess to use this. thanx again, inzo Quote he who forgets will be destined to remember... (E.Vedder)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.