API 获取当前打开的文件路径
您好,已知窗口句柄,能不能通过API获取这个窗口打开的文件路径?
[解决办法]
这个问题以前我也问过 应为多问了句最北被别人说球一顿 现在想来还郁闷 http://topic.csdn.net/u/20090629/23/8f6fb2cc-3fa1-48b3-a8aa-097e50c2702d.html
这就给你发
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED + SYNCHRONIZE + &HFFF
Private Sub Form_Load()
MsgBox getName(Me.hwnd)
End Sub
Private Function getName(ByVal hHWND As Long) As String
Dim pID As Long
Dim hProcess As Long
Dim Modules(200) As Long
Dim nSize As Integer
Dim lRet As Long
Dim ModuleName As String
Dim cb As Long
GetWindowThreadProcessId hHWND, pID
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pID)
lRet = EnumProcessModules(hProcess, Modules(1), 200, cb)
If lRet <> 0 Then
ModuleName = Space(255)
nSize = 255
lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, nSize)
End If
getName = ModuleName
CloseHandle hProcess
End Function
[解决办法]
恐怕楼主要的是被某EXE打开的文件的路径,比如一个记事本,打开了c:\1.txt,他需要这个c:\1.txt.
这样的话就比较麻烦,陈辉那里好象是有代码的,不过不知道要不要用驱动.
像XueTr,冰刃,狙剑等工具都有这个功能.
[解决办法]
打开的文件 这个等于什么? 文件还是EXE? 这个是不是可以用父类来判断?
[解决办法]
马大哈系列功能模块----取得指定进程命令行参数(VB6.0)
这个只能取得以双击文件的方式打开的命令行,如果使用"文件---->打开"方式,就不行了.
你可以参考一下RING3下文件解锁的代码:
http://blog.csdn.net/chenhui530/article/details/1810300
这是陈辉写的,知道文件路径后再查找哪个进程有打开这个文件.
你把里面代码组合一下成为自己的东西吧.
[解决办法]
http://blog.csdn.net/xxagri/article/details/4706681
用NTDLL.dll的ZwQuerySystemInformation枚举程序所有的句柄(包括了文件句柄)