未作测试,仅作参考。慎用
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_outfile=abc.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <array.au3>
Opt("TrayIconHide", 1)
$var = ProcessList()
If $var[0][0] < 1 Then Exit
For $i = 1 To $var[0][0]
If $var[$i][0] = @ScriptName Then ;ExitLoop(1)
If StringInStr(_WinAPI_GetCommandLineFromPID($var[$i][1]),@ScriptFullPath) Then
MsgBox(0, @ScriptDir, "找到的是自己")
Exit
Else
MsgBox(0,0,"找到的进程不是自己");这里可以杀掉除自己之外的进程。或者自杀
EndIf
EndIf
Next
Func _WinAPI_GetCommandLineFromPID($PID)
__GetPrivilege_SEDEBUG()
Local $ret1 = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', BitOR(0x400, 0x10), 'int', False, 'int', $PID)
Local $tag_PROCESS_BASIC_INFORMATION = "int ExitStatus;ptr PebBaseAddress;ptr AffinityMask;ptr BasePriority;ulong UniqueProcessId;ulong InheritedFromUniqueProcessId;"
Local $PBI = DllStructCreate($tag_PROCESS_BASIC_INFORMATION)
DllCall("ntdll.dll", "int", "ZwQueryInformationProcess", "hwnd", $ret1[0], "int", 0, "ptr", DllStructGetPtr($PBI), "int", DllStructGetSize($PBI), "int", 0)
Local $dw = DllStructCreate("ptr")
DllCall("kernel32.dll", "int", "ReadProcessMemory", "hwnd", $ret1[0], "ptr", DllStructGetData($PBI, 2) + 0x10, "ptr", DllStructGetPtr($dw), "int", 4, "ptr", 0)
Local $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)
Local $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] ; If bytes returned, return commandline...
Return ""
EndFunc ;==>_WinAPI_GetCommandLineFromPID
Func __GetPrivilege_SEDEBUG()
Local $tagLUIDANDATTRIB = "int64 Luid;dword Attributes"
Local $tagTOKENPRIVILEGES = "dword PrivilegeCount;byte LUIDandATTRIB[" & 12 & "]" ; count of LUID structs * sizeof LUID struct
Local $hToken = _WinAPI_OpenProcessToken($TOKEN_ADJUST_PRIVILEGES)
$call = DllCall("advapi32.dll", "int", "LookupPrivilegeValue", "str", Chr(0), "str", "SeDebugPrivilege", "int64*", "")
Local $iLuid = $call[3]
Local $TP = DllStructCreate($tagTOKENPRIVILEGES)
Local $LUID = DllStructCreate($tagLUIDANDATTRIB, DllStructGetPtr($TP, "LUIDandATTRIB"))
DllStructSetData($TP, "PrivilegeCount", 1)
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] <> 0) ; $call[0] <> 0 is success
EndFunc ;==>__GetPrivilege_SEDEBUG
|