• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Windows process status using a VB 6.0 Program

Dear Experts,

How to find out whether a process is running or exited on windows using a visual basic 6.0 program.

if i give the exe name , want to find out whether it is running
or not ?

Please help me

Thanks and Regards,
Prabhu
0
btprabhu
Asked:
btprabhu
2 Solutions
 
Steve SiricaSenior Web Application EngineerCommented:
Private Sub Form_Load()

Dim strComputer, strProcess
Do
   strProcess = InputBox("Please enter the name of the process (for instance: explorer.exe)", "Input")
Loop Until strProcess <> ""
Do
   strComputer = InputBox("Please enter the computer name", "Input")
Loop Until strComputer <> ""
If (IsProcessRunning(strComputer, strProcess) = True) Then
    Debug.Print "Process " & strProcess & " is running on computer " & strComputer
Else
    Debug.Print "Process " & strProcess & " is NOT running on computer " & strComputer
End If
End Sub


Function IsProcessRunning(strServer, strProcess)
    Dim Process, strObject
    IsProcessRunning = False
    strObject = "winmgmts://" & strServer
    For Each Process In GetObject(strObject).InstancesOf("win32_process")
        If UCase(Process.Name) = UCase(strProcess) Then
            IsProcessRunning = True
            Exit Function
        End If
    Next
End Function


just use localhost for the server and it should work fine.
0
 
EDDYKTCommented:
may be just

dim strProcess, colProcessList, objProcess

strProcess = "notepad.exe"

Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process Where Name ='" & strProcess & "'")

For Each objProcess in colProcessList
  objProcess.Terminate()
Next

Set colProcessList = Nothing
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now