Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • *Experts*
Posted

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 Function

It 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.

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...