Query remote CIM via WMI from Access Module

  • Thread starter Thread starter TR
  • Start date Start date
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
 
I use something like:

Dim objWMIService As SWbemServices 'SWbemObject
Dim colItems As SWbemObjectSet
Dim obj As SWbemObject
Set objWMIService = GetObject("winmgmts:\\" & strComputer
& "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * " & _
"FROM Win32_Process " & _
"WHERE Name = '" & FileName & "'", , 48)

For Each obj In colItems

Next Obj

Have a look at the following sites:

http://vbnet.mvps.org/index.html?code/wmi/index.html

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/wmisdk/wmi/wmi_start_page.asp

http://www.activexperts.com/activmonitor/windowsmanagement/
wmi/


(watch for wrapping)


Chris Nebinger


-----Original Message-----
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
 
Chris, This looks like it would work. However, how can I pass credentials in
the call?

This assumes that the caller has Admin on the remote machine..

TR
 
Back
Top