bungpeng Posted December 31, 2002 Posted December 31, 2002 Is there anyway I can defect whether a program is running? For example: 1. I have 2 program "A", and "B". 2. "A" program can trigger "B" program to run. (like Shell command in VB6) 3. But if "B" is already running, then "A" cannot ask "B" to run again. So, is there anyway I can defect whether "B" program is running? Thank you. Quote
*Gurus* divil Posted December 31, 2002 *Gurus* Posted December 31, 2002 If you're using Process.Start to start the other process, you can wait for the Exited event of the Process class returned to see when it has finished executing. You'll have to set .EnableRaisingEvents to true before it will raise the event though. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bungpeng Posted January 1, 2003 Author Posted January 1, 2003 No, the program is standalone and can run by itself, and now I want to defect it.... do you understand? Quote
*Gurus* divil Posted January 1, 2003 *Gurus* Posted January 1, 2003 I don't know what you mean by "defect", I can only assume you mean to say "detect" every time. There is a method of the process class that allows you to get a collection of all running processes on the system. Iterating through this should be able to tell you if your process is running or not. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bungpeng Posted January 2, 2003 Author Posted January 2, 2003 Sorry! I did a mistake, what you assume is right, it is "detect", not "defect". May I know what process class it is? that is what I looking for... Quote
*Experts* Volte Posted January 2, 2003 *Experts* Posted January 2, 2003 Here is a function that seems to work. Just pass it the name of the process (without extention [notepad, not notepad.exe, etc.]) and it will return a boolean value. Public Function IsProcessRunning(ByVal process As String) As Boolean Dim processes As Process(), tmp As New Process() processes = tmp.GetProcesses 'Enumerate the processes and check to see if the process is there For Each tmp In processes If tmp.ProcessName = process Then Return True Next Return False End FunctionIt could probably be optimized by some use of IndexOf, but since you can't create a Process object and then change its properties, it wouldn't work as easily as that. Quote
bungpeng Posted January 2, 2003 Author Posted January 2, 2003 May I know how to do the same thing if I use VB6? Quote
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.