Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

he who forgets will be destined to remember... (E.Vedder)
Posted

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

he who forgets will be destined to remember... (E.Vedder)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...