-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathWMIHelper.bas
More file actions
92 lines (58 loc) · 2.05 KB
/
WMIHelper.bas
File metadata and controls
92 lines (58 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Attribute VB_Name = "WMIHelper"
'--------------------------------------------------------------------------------
' Component : WMIHelper
' Project : ViDock
'
' Description: All routines that use WMI live here
' Windows Management Instrumentation
'
' Modified :
'--------------------------------------------------------------------------------
Private m_objWMIService
Private m_initialized As Boolean
Private Function InitializeIfRequired()
If m_initialized Then Exit Function
Set m_objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
m_initialized = True
End Function
'Very slow
Function GetProcessPath(pId As Long) As String
On Error GoTo Handler
If pId = 0 Then Exit Function
Dim szExePath As String
'Dim szCommandLine As String
Dim secondQuote As Long
On Error GoTo Handler
InitializeIfRequired
Set colItems = m_objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " & pId, , 48)
For Each objItem In colItems
szExePath = objItem.ExecutablePath
Next
GetProcessPath = szExePath
Handler:
End Function
'Very slow
Public Function GetProcessCommandLineArguments(pId As Long) As String
On Error GoTo Handler
If pId = 0 Then Exit Function
'Dim szExePath As String
Dim szCommandLine As String
Dim secondQuote As Long
On Error GoTo Handler
InitializeIfRequired
Set colItems = m_objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " & pId, , 48)
For Each objItem In colItems
szCommandLine = objItem.CommandLine
Next
If Len(szCommandLine) < 2 Then
GetProcessCommandLineArguments = Trim(szCommandLine)
Exit Function
End If
secondQuote = InStr(2, szCommandLine, """")
If secondQuote > 0 Then
GetProcessCommandLineArguments = TrimNull(Mid$(szCommandLine, secondQuote + 1))
Exit Function
End If
Handler:
GetProcessCommandLineArguments = TrimNull(szCommandLine)
End Function