Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check to see if a program is running, if not, then start it? 1

Status
Not open for further replies.

Homersim2600

Technical User
Dec 15, 2004
253
US
Hello,
I have done this before, and I know that it is rather easy, however, my memory fails me as to how to programatically go about checking to see if a program is running, if it is, then cool, if not, then I will need to start it.

A little background... I am writing a program that will make the installation of WordPress, a really nice Journal maker/blogger, easier, and I need to check to see if MysqlD.exe (the server) is running before configuring the database.

Thank you folks.

LF



"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Code:
    Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    
    Set colprocesses = obj.ExecQuery("SELECT * FROM Win32_Process WHERE Name='MySqlD.exe'")

    If colprocesses.Count > 0 Then
        'It is running
    Else
        'It is not running
    End If

Also, see the link I provided for WMI doc in thread222-983444
 
bjd4jc,

Thank you for your reply. However, this is not working for me. I went to the link you posted in the other forum and read all of the information. Apparently, this code will not work with Windows NT, which is what I am currently running.

Also, this is not the method I have used in the past. Don't get me wrong, this is an awesome function, it just doesn't meet my current needs. The method I used to use dealt with the API, I am still scouring the internet to see if I can find it, but am currently having no luck.

Again, thank you for your responce...

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
I should also mention that the server will most likely be running on the local machine; at least 9 out of 10 times.

Thanks

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Please see the code I posted in thread222-63270

This is the API method of doing this.

Sorry about the previous post. I guess I just assume that people have XP unless stated otherwise - bad assumption on my part.

If you're interested you can download WMI for NT and the above code will work for you.

The code in the above mentioned thread would need to be adapted to meet your needs a little bit. I think it was originally designed to terminate an application which is running - but it terminates by exe name.

Post back if you have specific questions about the code.
 
bjd4jc,

Thank you! This is what I was looking for.

Yeah, I tried to download the WMI and it said that my OS is not supported. Gheesh! I have XP at home, but here at work I am a limited user on an NT machine. There may be a version of it for NT but I just grabbed the first one I saw :). Ok, well I think I will be able to do what I need to do with what you have provided me. I appreciate your help, and I will certainly post back if I have problems; for the future scavenger... ;-)

Thanks again...

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
vladk,

No my application is not windowless. However, when MySQLD.exe is running it is windowless. With a few modifications to bjd4jc's code, I was able to get what I needed. Thank you for your inquiry.

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top