20分。VB怎样获取正在运行的文件句柄。?

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:12:09
用下面这段代码可以获取某正在运行进程文件的句柄,可返回值都是0,怎么改下?。。
http://topic.csdn.net/u/20070925/11/c0fa3831-e732-46f2-81e3-2465d0577151.html?1416895339

那个页面的是(Ring3下解锁文件的模块)

你要获取某正在运行进程文件的句柄这个可以用 遍历进程池 或者 FINDWINDOW 实现。

枚举进程的例子

'模块
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'该函数是EnumWindows的回调函数,EnumWindows函数将遍历的窗口句柄传递到hwnd参数中
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim astr As String * 256
Dim l As Long
l = GetWindowText(hwnd, astr, Len(astr))
If InStr(astr, Chr$(0)) > 1 Then Form1.List1.AddItem hwnd & vbTab & ": " & astr
EnumWindowsProc = True
End Function

'窗体
'放一个ListBox:List1
Private Sub Form_Load()
'遍历所有的窗口
EnumWindows AddressOf EnumWindowsProc, 0
End Sub