Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-09-2009
Member
 
Join Date: Jul 2009
Posts: 36
Check if process is running on Local Machine using VB script

Hi friends,

Whenever i am using my machine i see that most of the time unwanted process are running and at the end the slow down my computer speed. At the same time when i try to shut down my system it takes a very long time to shut down it says that some of the process are still running which needs to be closed before shutting down. According to me we can have a check if the process is running on Local Machine or not by using VB script. I have try to write some code but it was wrong. Can anyone help me out with this issue.
Reply With Quote
  #2  
Old 03-09-2009
Member
 
Join Date: Jan 2009
Posts: 110
Re: Check if process is running on Local Machine using VB script

If you want to check if a process is running on Local Machine then you need to use the following code.

Code:
strComputer = "."
Set objWMIService1 = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService1. _        
    ExecNotificationQuery("select * from __instancecreationevent " _ 
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
    Set objLatest_Process = colMonitoredProcesses.NextEvent
    If objLatest_Process.TargetInstance.Name = "cscript.exe" or  _
       objLatest_Process.TargetInstance.Name = "wscript.exe Then
         wscript.echo "This program is currently running.  You will be notified once it completes."
         wscript.quit 'may want to destroy any objects here as well.
    Else
         'place your script code here...
    End If
Loop
Reply With Quote
  #3  
Old 03-09-2009
Member
 
Join Date: Jul 2009
Posts: 36
Re: Check if process is running on Local Machine using VB script

I have try to use the above code which you have provided me but still i am not able to check whether the process is running on Local Machine using VB script. Can anyone provide me correct code for it. Thanks in Advance.
Reply With Quote
  #4  
Old 03-09-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Check if process is running on Local Machine using VB script

Try to use the below code i was able to check if process is running on Local Machine using VB script, i am sure this code will definitely work for you.

Code:
Function IsProcess_Running( strServer, strProcess )
    Dim Process, strObject
    IsProcess_Running = 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

' ****************************************************************************
' Main
' ****************************************************************************
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( IsProcess_Running( strComputer, strProcess ) = True ) Then
    WScript.Echo "Process " & strProcess & " is running on computer " & strComputer
Else
    WScript.Echo "Process " & strProcess & " is NOT running on computer " & strComputer
End If
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Check if process is running on Local Machine using VB script"
Thread Thread Starter Forum Replies Last Post
Local Security Authority Process is using more RAM and CPU memory. Akalbir Windows Software 8 19-10-2011 04:40 PM
Running script on remote machine SuderMan Windows Server Help 12 25-08-2010 06:51 PM
Script to add a machine to domain martinez7251 Windows Software 1 11-05-2010 11:23 PM
How to get list of Local Interfaces on a machine? Henryosa Software Development 3 05-12-2009 02:52 PM
How to check if the process is running without using ps Sachit Operating Systems 3 03-07-2009 02:22 PM


All times are GMT +5.5. The time now is 01:10 PM.