求结束多个进程名称其中一个的方法
本帖最后由 qq724174 于 2011-3-27 18:37 编辑例如有3个abc.exe进程
路径分别是
C:\WINDOWS\ABC.EXE
C:\WINDOWS\SYSTEM32\ABC.EXE
C:\WINDOWS\SYSTEM32\TEST\ABC.EXE
要结束C:\WINDOWS\SYSTEM32\TEST\ABC.EXE却不影响其他两个ABC.exe
求大家指点。
或者告诉我个已经进程全路径取进程PID的方法也行,谢谢了。 #include <WinAPI.au3>
#include <array.au3>
Global Const $PROCESS_VM_READ=0x10
Global Const $PROCESS_QUERY_INFORMATION = 0x400
_GetPrivilege_SEDEBUG()
$list=ProcessList()
Redim $list
for $i=1 to ubound($list,1)-1
$list[$i]=_WinAPI_GetCommandLineFromPID($list[$i])
Next
_ArrayDisplay($list)
Exit
Func _WinAPI_GetCommandLineFromPID($PID)
$ret1=DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_VM_READ+$PROCESS_QUERY_INFORMATION, 'int', False, 'int', $PID)
$tag_PROCESS_BASIC_INFORMATION = "int ExitStatus;" & _
"ptr PebBaseAddress;" & _
"ptr AffinityMask;" & _
"ptr BasePriority;" & _
"ulong UniqueProcessId;" & _
"ulong InheritedFromUniqueProcessId;"
$PBI=DllStructCreate($tag_PROCESS_BASIC_INFORMATION)
DllCall("ntdll.dll", "int", "ZwQueryInformationProcess", "hwnd", $ret1, "int", 0, "ptr", DllStructGetPtr($PBI), "int", _
DllStructGetSize($PBI), "int",0)
$dw=DllStructCreate("ptr")
DllCall("kernel32.dll", "int", "ReadProcessMemory", "hwnd", $ret1, _
"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, _
"ptr", DllStructGetData($dw, 1)+0x40, _
"ptr", DllStructGetPtr($unicode_string), "int", DllStructGetSize($unicode_string), "ptr", 0)
$ret=DllCall("kernel32.dll", "int", "ReadProcessMemory", "hwnd", $ret1, _
"ptr", DllStructGetData($unicode_string, "String"), _
"wstr", 0, "int", DllStructGetData($unicode_string, "Length") + 2, "int*", 0)
DllCall("kernel32.dll", 'int', 'CloseHandle', "hwnd", $ret1)
If $ret Then Return $ret
Return ""
EndFunc
Func _GetPrivilege_SEDEBUG()
Local $tagLUIDANDATTRIB = "int64 Luid;dword Attributes"
Local $count = 1
Local $tagTOKENPRIVILEGES = "dword PrivilegeCount;byte LUIDandATTRIB[" & $count * 12 & "]"
Local $TOKEN_ADJUST_PRIVILEGES = 0x20
Local $call = DllCall("advapi32.dll", "int", "OpenProcessToken", "ptr", _WinAPI_GetCurrentProcess(), "dword", $TOKEN_ADJUST_PRIVILEGES, "ptr*", "")
Local $hToken = $call
$call = DllCall("advapi32.dll", "int", "LookupPrivilegeValue", "str", Chr(0), "str", "SeDebugPrivilege", "int64*", "")
Local $iLuid = $call
Local $TP = DllStructCreate($tagTOKENPRIVILEGES)
Local $LUID = DllStructCreate($tagLUIDANDATTRIB, DllStructGetPtr($TP, "LUIDandATTRIB"))
DllStructSetData($TP, "PrivilegeCount", $count)
DllStructSetData($LUID, "Luid", $iLuid)
DllStructSetData($LUID, "Attributes", $SE_PRIVILEGE_ENABLED)
$call = DllCall("advapi32.dll", "int", "AdjustTokenPrivileges", "ptr", $hToken, "int", 0, "ptr", DllStructGetPtr($TP), "dword", 0, "ptr", Chr(0), "ptr", Chr(0))
Return ($call <> 0)
EndFunc 本帖最后由 zitoy 于 2011-3-27 20:35 编辑
通过PID获取路径,再对比。
;~ 查找进程对应文件路径
Func _Processpath($iPID)
Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
If $aProc = 0 Then Return SetError(1, 0, '')
Local $vStruct = DllStructCreate('int')
DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc, 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc, 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
If StringLen($aReturn) = 0 Then Return SetError(2, 0, '')
Return $aReturn
EndFunc ;==>_Processpath 学习了,收藏,日后备用 收藏备用3#的思路不错值得学习一下2#代码有些高深看上去比较眼晕
页:
[1]