找回密码
 加入
搜索
查看: 5294|回复: 14

[AU3基础] [已解决]_WinAPI_GetProcessWorkingDirectory显示的进程路径相当部分是错误的

 火.. [复制链接]
发表于 2015-6-11 08:07:20 | 显示全部楼层 |阅读模式
本帖最后由 smooth 于 2015-6-17 09:22 编辑

_WinAPI_GetProcessWorkingDirectory显示的进程路径相当部分是错误的。

程序版本:  3.3.9.21,操作系统:Windows 7旗舰版 X64中文版。

并且在64位系统下,如果脚本带了#PRE_UseX64=n,则大部分的进程的工作目录无法获取。
发表于 2015-6-11 08:17:19 | 显示全部楼层
用管理员帐户 #RequireAdmin
 楼主| 发表于 2015-6-11 11:44:59 | 显示全部楼层
用管理员帐户 #RequireAdmin
haijie1223 发表于 2015-6-11 08:17


已经插入了#RequireAdmin的。
发表于 2015-6-11 15:38:31 | 显示全部楼层
把你获取的内容上图看下~
 楼主| 发表于 2015-6-11 17:12:38 | 显示全部楼层
把你获取的内容上图看下~
haijie1223 发表于 2015-6-11 15:38


红色框住的,我觉得都有点问题。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2015-6-11 18:57:29 | 显示全部楼层
用getcommandline,然后拆
 楼主| 发表于 2015-6-11 21:55:41 | 显示全部楼层
本帖最后由 smooth 于 2015-6-11 22:23 编辑
用getcommandline,然后拆
netegg 发表于 2015-6-11 18:57


在百度里搜索了一下,找到这个函数了,但是我不管是用MsgBox还是用_ArrayDisplay(),都接收不到返回值,请问一下这个函数的参数是什么呢?

Func _WinAPI_GetCommandLine($PID = 0)
    If Not $PID Then $PID = @AutoItPID
    $ret1=DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x00000410, 'int', False, 'int', $PID)
    $PBI=DllStructCreate("int ExitStatus;ptr PebBaseAddress;ptr AffinityMask;ptr BasePriority;ulong UniqueProcessId;ulong InheritedFromUniqueProcessId;")
    DllCall("ntdll.dll", "int", "ZwQueryInformationProcess", "hwnd", $ret1[0], "int", 0, "ptr", DllStructGetPtr($PBI), "int", DllStructGetSize($PBI), "int", 0)
    $dw=DllStructCreate("ptr")
    DllCall("kernel32.dll", "int", "ReadProcessMemory", "hwnd", $ret1[0], "ptr", DllStructGetData($PBI,2)+0x10, "ptr", DllStructGetPtr($dw), "int", 4, "ptr", 0)
    $unicode_string = DllStructCreate("ushort Length;ushort MaxLength;ptr String")
    DllCall("kernel32.dll", "int", "ReadProcessMemory", "hwnd", $ret1[0], "ptr", DllStructGetData($dw, 1)+0x40, "ptr", DllStructGetPtr($unicode_string), "int", DllStructGetSize($unicode_string), "ptr", 0)
    $ret=DllCall("kernel32.dll", "int", "ReadProcessMemory", "hwnd", $ret1[0], "ptr", DllStructGetData($unicode_string, "String"), "wstr", 0, "int", DllStructGetData($unicode_string, "Length") + 2, "int*", 0)
    DllCall("kernel32.dll", 'int', 'CloseHandle', "hwnd", $ret1[0])
    If $ret[5] Then Return $ret[3]
    Return ""
EndFunc
发表于 2015-6-12 17:35:19 | 显示全部楼层
xp下测试也是不很准确,换个函数吧,在论坛搜索到的。
#RequireAdmin
#include <Array.au3>

$aList = ProcessList()
For $i = 1 To $aList[0][0]
        $aList[$i][1] = _GetModuleFileNameEx($aList[$i][1])
Next

_ArrayDisplay($aList, '_GetModuleFileNameEx')

Func _GetModuleFileNameEx($_Pid)
        $_Hwnd = DllCall("Kernel32.dll", "hwnd", "OpenProcess", "dword", 0x0400 + 0x0010, "int", 0, "dword", $_Pid)
        $_Return = DllCall("Psapi.dll", "long", "GetModuleFileNameEx", "hwnd", $_Hwnd[0], "long", 0, "str", 0, "long", 255)
        DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $_Hwnd[0])
        If StringInStr($_Return[3], "") Then Return $_Return[3]
        Return ""
EndFunc   ;==>_GetModuleFileNameEx
发表于 2015-6-13 12:20:12 | 显示全部楼层
回复 7# smooth
先用processlist枚举出pid
 楼主| 发表于 2015-6-14 09:03:09 | 显示全部楼层
回复  smooth
先用processlist枚举出pid
netegg 发表于 2015-6-13 12:20


这个函数本来就是先用processlist枚举出pid的,我一直也是这样想的,但是枚举出PID之后,还必须搞到EXE所在的路径,这样和PID结合,才能准确删除。这也就是上面这个函数的功能。现在就是这个段函数有些问题,枚举出来的路径很多是不准确的。
 楼主| 发表于 2015-6-14 11:16:58 | 显示全部楼层
xp下测试也是不很准确,换个函数吧,在论坛搜索到的。
haijie1223 发表于 2015-6-12 17:35


这个函数准是准了,但是很多进程都没有显示路径。
发表于 2015-6-16 14:57:37 | 显示全部楼层
回复 11# smooth
DllCall('ntdll','LONG','RtlAdjustPrivilege','ULONG',0x14,'BYTE',1,'BYTE',0,'BYTE*',0)

加在OpenProcess前
 楼主| 发表于 2015-6-17 09:21:33 | 显示全部楼层
回复 12# ceoguang

按照你的建议,问题得到解决,非常感谢!

#RequireAdmin
#include <Array.au3>

$aList = ProcessList()
For $i = 1 To $aList[0][0]
        $aList[$i][1] = _GetModuleFileNameEx($aList[$i][1])
Next

_ArrayDisplay($aList, '_GetModuleFileNameEx')

Func _GetModuleFileNameEx($_Pid)
        DllCall('ntdll', 'LONG', 'RtlAdjustPrivilege', 'ULONG', 0x14, 'BYTE', 1, 'BYTE', 0, 'BYTE*', 0)
        $_Hwnd = DllCall("Kernel32.dll", "hwnd", "OpenProcess", "dword", 0x0400 + 0x0010, "int", 0, "dword", $_Pid)
        $_Return = DllCall("Psapi.dll", "long", "GetModuleFileNameEx", "hwnd", $_Hwnd[0], "long", 0, "str", 0, "long", 255)
        DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $_Hwnd[0])
        If StringInStr($_Return[3], "\") Then Return $_Return[3]
        Return ""
EndFunc   ;==>_GetModuleFileNameEx

发表于 2015-6-17 17:11:45 | 显示全部楼层
学习了,我之前就是为了工作目录的事头疼了很久
发表于 2016-12-16 02:57:49 | 显示全部楼层
学习了,终于搞定了这个难题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-26 18:09 , Processed in 0.089073 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表