Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Process Information Remotely 3

Status
Not open for further replies.

KeyserSoze1877

Programmer
Sep 6, 2001
95
US
I have 30+ servers all running the same services.
I have a mystery problem of the service running up and sucking up all the memory on a server.

Without manually checking each server, I am growing to 100+ by years end, I would like to do this.

Can I remotely see what processes are running on a server and see the current memory usage for said process?

---------------
Keyser Soze
"There are no stupid questions, just stupid people.
 
Here is some code that I have in my library that does this. I haven't tested it recently.

Code:
Public Function IsProcessRunningOnRemoteComputer(ComputerName As String, ProcessName As String) As Long
'This function has the following return values
'   0 if the process is running on the remote computer
'   1 if the process is not running
    Dim ProcCount As Integer
    
    ProcCount = 0
    On Error Resume Next
    Set objwmiservice = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2")

    If Err.Number <> 0 Then
        IsProcessRunningOnRemoteComputer = ProcCount
        Exit Function
    End If

    Set colProcesses = objwmiservice.ExecQuery("select * from win32_process")
    For Each objprocess In colProcesses
        If UCase(objprocess.Caption) = UCase(ProcessName) Then
            ProcCount = ProcCount + 1
        End If
    Next
    
    IsProcessRunningOnRemoteComputer = ProcCount
    Set objprocess = Nothing
    Set colprocess = Nothing
    Set objwmiservice = Nothing
End Function

Here is how you would call it:
Code:
Debug.print IsProcessRunningOnRemoteComputer("172.16.81." & LCV, "YourExe.exe")

I believe that the function can take either an IP Address or a computer name. Like I said, it's been a while since I've used it.

The client PC would require the use of WMI. Older version of windows do not include this by default. You can download it from Microsoft if your pc doesn't have it.
 
That's pretty cool! Is there a way to remotely kill and/or start processes too?


Meddle not in the affairs of dragons,
for you are crunchy, and good with mustard.
 
Yeah, that is cool...

I'll give you a star for that one ;-)
 
Thanks, CubeE! I was introduced to WMI by strongm. It has since caught my attention and I have learned to do lots of stuff remotely like this.
 
Sorry, my rudeness... I forgot to give you a star for that one too, and I should know better.


Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Code:
    Set obj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    
    Set colprocesses = obj.ExecQuery("SELECT * FROM Win32_Process WHERE Name='MySqlD.exe'")

    If colprocesses.Count > 0 Then
        'It is running
    Else
        'It is not running
    End If
 
Great help so far... However..

I have not found the code to read a process' current Physical Memory useage and Virtual Memory useage. I found the Win32_Process class, but that does not contain those properties.

Anyone know without directing to another website?

---------------
Keyser Soze
"There are no stupid questions, just stupid people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top