Private Type PROCESS_BASIC_INFORMATION
ExitStatus As Long
PebBaseAddress As Long
AffinityMask As Long
BasePriority As Long
UniqueProcessId As Long
InheritedFromUniqueProcessId As Long
End Type
Private Declare Function NtQueryInformationProcess _
Lib "ntdll" (ByVal ProcessHandle As Long, _
ByVal ProcessInformationClass As Long, _
ByRef ProcessInformation As PROCESS_BASIC_INFORMATION, _
ByVal lProcessInformationLength As Long, _
ByRef lReturnLength As Long) As LongPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public ProcessHandle As Long
Public Function GetProcessID(ByVal ProcessHandle As Long) As Long
On Error GoTo e
Dim info As PROCESS_BASIC_INFORMATION
If NtQueryInformationProcess(ProcessHandle, 0, info, Len(info), ByVal 0&) = 0 Then
GetProcessID = info.UniqueProcessId
Else
GetProcessID = 1
End If
e: End Function
frm
Private Sub Command1_Click()
a = FindWindow(vbNullString, "Windows 任务管理器")
Print a
Print GetProcessID(a)
End Sub
为什么NtQueryInformationProcess 总执行错误呢??????
在问一下,有没有关于ZW*和NT*开头的API函数帮助呢???
谢谢!!!!!!!!!!!!!
ExitStatus As Long
PebBaseAddress As Long
AffinityMask As Long
BasePriority As Long
UniqueProcessId As Long
InheritedFromUniqueProcessId As Long
End Type
Private Declare Function NtQueryInformationProcess _
Lib "ntdll" (ByVal ProcessHandle As Long, _
ByVal ProcessInformationClass As Long, _
ByRef ProcessInformation As PROCESS_BASIC_INFORMATION, _
ByVal lProcessInformationLength As Long, _
ByRef lReturnLength As Long) As LongPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public ProcessHandle As Long
Public Function GetProcessID(ByVal ProcessHandle As Long) As Long
On Error GoTo e
Dim info As PROCESS_BASIC_INFORMATION
If NtQueryInformationProcess(ProcessHandle, 0, info, Len(info), ByVal 0&) = 0 Then
GetProcessID = info.UniqueProcessId
Else
GetProcessID = 1
End If
e: End Function
frm
Private Sub Command1_Click()
a = FindWindow(vbNullString, "Windows 任务管理器")
Print a
Print GetProcessID(a)
End Sub
为什么NtQueryInformationProcess 总执行错误呢??????
在问一下,有没有关于ZW*和NT*开头的API函数帮助呢???
谢谢!!!!!!!!!!!!!
findwindow取出来的是窗体句柄(winhwnd),而ProcessHandle指的是进程打开的句柄Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Longwinhwnd= FindWindow(vbNullString, "Windows 任务管理器")
call GetWindowThreadProcessId(winhwnd, ProcessID)ProcessID才是你想要的进程id
参数直接传给了 NtQueryInformationProcess
要传进程句柄