query WMI from within Access

M

MSFT

I'm sure it is possible, however I'm not having any luck.

The question is how do a query WMI from within Access?

I haven't used Access in a long time, but I believe its an onbject reference
problem and I'm unable to find any syntax info that can help.

All examples online are using WSH

Any help would be greatly appreciated


TR
 
C

Chris \( Val \)

| I'm sure it is possible, however I'm not having any luck.
|
| The question is how do a query WMI from within Access?
|
| I haven't used Access in a long time, but I believe its an onbject reference
| problem and I'm unable to find any syntax info that can help.
|
| All examples online are using WSH
|
| Any help would be greatly appreciated

In the references, you will need to add(if installed):
MS WMI Scripting 1.2 Library
And most probably Microsoft Scripting Runtime

Then you can try this sample:

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

Good luck.
Chris Val
 
M

MSFT

That did the trick.

I was not reference Wbemscripting properly...Thanks for the quick reply and
working solution..

TR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top