T
TR
Chis (Val) was able to give me a solution to this . However, the solution
is for a local machine only.
I've been unable to query a remote machine. I've tried passing the perams
in the Locator.ConnectServer, but continue to get an RPC error or automation
error.
Below is the solution given by Chris. Again it does work for local but not
remote
Option Explicit
Private Function GetPID(ByVal FileName As String) As Integer
'
Dim Locator As WbemScripting.SWbemLocator
Dim Service As WbemScripting.SWbemServices
Dim ServiceProperty As SWbemObjectSet
Dim Query As String
Dim Process As Object
Query = "SELECT * " & _
"FROM Win32_Process " & _
"WHERE Name = '" & FileName & "'"
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.ConnectServer()
Set ServiceProperty = Service.ExecQuery(Query)
If ServiceProperty.Count > 0 Then
For Each Process In ServiceProperty
MsgBox "Process: " & Process.Name & vbNewLine & _
"Process ID: " & Process.ProcessID & vbNewLine & _
"Thread Count: " & Process.ThreadCount & vbNewLine & _
"Page File Size: " & Process.PageFileUsage & vbNewLine & _
"Page Faults: " & Process.PageFaults & vbNewLine & _
"Working Set Size: " & Process.WorkingSetSize & vbNewLine
Next
Else
MsgBox FileName & " not found in service list", vbCritical, "SERVICE
QUERY"
End If
'
End Function
Private Sub Command1_Click()
'
GetPID ("notepad.exe")
'
End Sub
Any help would be greatly appreciated
is for a local machine only.
I've been unable to query a remote machine. I've tried passing the perams
in the Locator.ConnectServer, but continue to get an RPC error or automation
error.
Below is the solution given by Chris. Again it does work for local but not
remote
Option Explicit
Private Function GetPID(ByVal FileName As String) As Integer
'
Dim Locator As WbemScripting.SWbemLocator
Dim Service As WbemScripting.SWbemServices
Dim ServiceProperty As SWbemObjectSet
Dim Query As String
Dim Process As Object
Query = "SELECT * " & _
"FROM Win32_Process " & _
"WHERE Name = '" & FileName & "'"
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.ConnectServer()
Set ServiceProperty = Service.ExecQuery(Query)
If ServiceProperty.Count > 0 Then
For Each Process In ServiceProperty
MsgBox "Process: " & Process.Name & vbNewLine & _
"Process ID: " & Process.ProcessID & vbNewLine & _
"Thread Count: " & Process.ThreadCount & vbNewLine & _
"Page File Size: " & Process.PageFileUsage & vbNewLine & _
"Page Faults: " & Process.PageFaults & vbNewLine & _
"Working Set Size: " & Process.WorkingSetSize & vbNewLine
Next
Else
MsgBox FileName & " not found in service list", vbCritical, "SERVICE
QUERY"
End If
'
End Function
Private Sub Command1_Click()
'
GetPID ("notepad.exe")
'
End Sub
Any help would be greatly appreciated