Results 1 to 4 of 4

Thread: Check if process is running on Local Machine using VB script

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

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

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

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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

Similar Threads

  1. Replies: 8
    Last Post: 19-10-2011, 04:40 PM
  2. Running script on remote machine
    By SuderMan in forum Windows Server Help
    Replies: 12
    Last Post: 25-08-2010, 06:51 PM
  3. Script to add a machine to domain
    By martinez7251 in forum Windows Software
    Replies: 1
    Last Post: 11-05-2010, 11:23 PM
  4. How to get list of Local Interfaces on a machine?
    By Henryosa in forum Software Development
    Replies: 3
    Last Post: 05-12-2009, 02:52 PM
  5. How to check if the process is running without using ps
    By Sachit in forum Operating Systems
    Replies: 3
    Last Post: 03-07-2009, 02:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,306,305.65522 seconds with 17 queries