#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=z:\portablesync\au3project\source\pr\pr.kxf
$Form1_1 = GUICreate("Form1", 935, 783, 192, 114)
$ListView1 = GUICtrlCreateListView("进程名称|PID|映像路径|公司名称|描述", 0, 24, 930, 454)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 190)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 230)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 170)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, -2)
$Tab1 = GUICtrlCreateTab(8, 488, 921, 289, BitOR($TCS_FLATBUTTONS,$TCS_BUTTONS,$TCS_MULTILINE), $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
$TabSheet1 = GUICtrlCreateTabItem(" 动态链接(DLLs) ")
$ListView2 = GUICtrlCreateListView("模块句柄|模块路径|公司名称|描述", 15, 522, 906, 246, $LVS_NOSORTHEADER, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 290)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 190)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, -2)
$TabSheet2 = GUICtrlCreateTabItem(" 禁止加载(Ban) ")
$TabSheet3 = GUICtrlCreateTabItem(" 加载记录(Log) ")
$Edit1 = GUICtrlCreateEdit("", 15, 519, 905, 281, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlCreateTabItem("")
$Checkbox1 = GUICtrlCreateCheckbox("禁止所有加载", 352, 496, 97, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#include <Array.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>
;~ #include <lsasecur.au3>
#include <LocalSecurityAuthority.au3>
Global Enum $UnModule = 1000
$Menu1 = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($Menu1, 0, "卸载模块", $UnModule)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $_PROC=_PEx_EnumProcess(4000)
For $i = 1 To $_PROC[0][0]
GUICtrlCreateListViewItem( _ArrayToString($_PROC, "|" , $i, $i), $ListView1)
If $_PROC[$i][3] <> 'Microsoft Corporation' Then GUICtrlSetColor(-1, '0xFF0000')
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView1, $hWndListView2, $SelectedID, $hWndTab
Local $_PHandle,$_PCompanyName,$_PPath
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
If Not IsHWnd($ListView1) Then $hWndListView1 = GUICtrlGetHandle($ListView1)
If Not IsHWnd($ListView2) Then $hWndListView2 = GUICtrlGetHandle($ListView2)
Switch $hWndFrom ;选择产生事件的控件
Case $hWndListView1
Switch $iCode ; 选择产生的事件
Case $NM_CLICK ; 左击
_GUICtrlListView_DeleteAllItems($ListView2)
$_INDEX = _GUICtrlListView_GetSelectedIndices($ListView1)
$_SelectListView1=_GUICtrlListView_GetSelectedIndices($ListView1)
If StringIsDigit ($_SelectListView1) == 0 Then ContinueCase
$_PModule = _WinAPI_EnumProcessModules($_PROC[$_SelectListView1 + 1][1], $LIST_MODULES_ALL)
;~ _ArrayDisplay($_PModule)
If IsArray($_PModule) Then
For $i = 1 To $_PModule[0][0]
$_PHandle=$_PModule[$i][0]
$_PPath=$_PModule[$i][1]
$_PPath = StringRegExpReplace ( $_PPath, "\\SystemRoot","C:\\windows")
$_PCompanyName = FileGetVersion($_PPath, 'CompanyName')
$_PFileDescription = FileGetVersion($_PPath, 'FileDescription')
If $_PCompanyName <> 'Microsoft Corporation' Then
GUICtrlCreateListViewItem( _ArrayToString($_PModule, "|" , $i, $i)&'|'&$_PCompanyName&'|'&$_PFileDescription, $ListView2)
GUICtrlSetColor(-1, '0xFF0000')
EndIf
Next
EndIf
Case $NM_DBLCLK ; 双击
Case $NM_RCLICK ; 右击
EndSwitch
Case $hWndListView2
Switch $iCode ; 选择产生的事件
Case $NM_RCLICK ; 右击
If _GUICtrlListView_GetSelectedIndices($hWndListView2) = "" Then
_GUICtrlMenu_SetItemDisabled($Menu1, 0)
Else
_GUICtrlMenu_SetItemEnabled($Menu1, 0)
EndIf
$SelectedID = _GUICtrlMenu_TrackPopupMenu($Menu1, $hWndListView2, -1, -1, 1, 1, 2)
Switch $SelectedID
Case $UnModule
$_INDEX = _GUICtrlListView_GetSelectedIndices($hWndListView2)
$_SelectListView1 = _GUICtrlListView_GetSelectedIndices($hWndListView1)
$_ListView1_PID=_GUICtrlListView_GetItemText($hWndListView1, $_SelectListView1, 1)
$_ListView2_DLL=_GUICtrlListView_GetItemText($hWndListView2, $_INDEX, 1)
MsgBox(0, $_ListView1_PID,$_ListView2_DLL )
_UnloadDll($_ListView1_PID, $_ListView2_DLL)
_UnloadDll(4, _GUICtrlListView_GetItemText($hWndListView2, $_INDEX, 1))
;~ RunWait('Unlocker.exe '&_GUICtrlListView_GetItemText ($hWndListView2, $_INDEX,2)&' /S /D')
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _PEx_EnumProcess($iMaxID = 65535) ;65535
Local $_PROCESS_INDEX[1][5]
Local $h_Process[1][1], $iElement, $h_pro, $d_PName, $d_IsHide
For $i = 0 To $iMaxID
$_PHandle = _WinAPI_OpenProcess(0x00000410, 0, $i)
If Not $_PHandle Then ContinueLoop;https://msdn.microsoft.com/en-us/library/windows/desktop/ms686769(v=vs.85).aspx
$_PPath = _WinAPI_GetModuleFileNameEx($_PHandle)
If @error Then ContinueLoop
$_PName = _WinAPI_GetProcessName($i)
$_PPath = StringRegExpReplace ( $_PPath, "\\SystemRoot","C:\\windows")
$_PCompanyName = FileGetVersion($_PPath, 'CompanyName')
$_PFileDescription = FileGetVersion($_PPath, 'FileDescription')
$x = UBound($_PROCESS_INDEX)
ReDim $_PROCESS_INDEX[$x + 1][5]
$_PROCESS_INDEX[$x][0] = $_PName
$_PROCESS_INDEX[$x][1] = $i
$_PROCESS_INDEX[$x][2] = $_PPath
$_PROCESS_INDEX[$x][3] = $_PCompanyName
$_PROCESS_INDEX[$x][4] = $_PFileDescription
$i += 3
_WinAPI_CloseHandle($_PHandle)
Next
$_PROCESS_INDEX[0][0] = UBound($_PROCESS_INDEX) - 1
Return $_PROCESS_INDEX
EndFunc ;==>_PEx_EnumProcess
Func _PEx_EnumModules($iPID, $iSafe = 1, $iFlag = 3)
If Not ProcessExists($iPID) Then Return SetError(1);非有效进程
Local $i, $_Modules[1][3]
$_ENUM_MODULE = _WinAPI_EnumProcessModules($iPID, $iFlag) ;检索指定进程中每个模块的句柄和名称. $LIST_MODULES_ALL=3(所有模块)
If $iSafe == 1 Then
For $i = 1 To $_ENUM_MODULE[0][0]
$_CompanyName = FileGetVersion($_ENUM_MODULE[$i][1], 'CompanyName')
If $_CompanyName <> 'Microsoft Corporation' Then
ReDim $_Modules[UBound($_Modules) + 1][3]
$_Modules[UBound($_Modules) - 1][0] = $_ENUM_MODULE[$i][0]
$_Modules[UBound($_Modules) - 1][1] = $_ENUM_MODULE[$i][1]
$_Modules[UBound($_Modules) - 1][2] = $_CompanyName
EndIf
Next
EndIf
$_Modules[0][0] = UBound($_Modules) - 1
Return $_Modules
EndFunc ;==>_PEx_EnumModules
Func _UnloadDll($iProcessID, $sModule)
Local $aModule, $hModule, $pFreeLibrary, $hThread, $hProcess
Local $hToken, $aPriv[1][2] = [[$SE_DEBUG_NAME, 2]], $iFlags
$hToken = _OpenProcessToken(-1)
_AdjustTokenPrivileges($hToken, $aPriv)
_LsaCloseHandle($hToken)
$hProcess = _OpenProcess($iProcessID)
If $hProcess < 1 Then Return SetError(@error, 0, 0)
$sModule = _GetFullPathName($sModule)
$hModule = _GetModuleHandle("Kernel32.dll")
$pFreeLibrary = _GetProcAddress($hModule, "FreeLibrary")
$aModule = _EnumProcessModules($hProcess)
For $i = 1 To $aModule[0][0]
;~ If FileGetVersion($aModule[$i][1],'CompanyName') <> 'Microsoft Corporation' Then MsgBox(0, '', $aModule[$i][1])
If $aModule[$i][1] <> $sModule Then ContinueLoop
$hThread = _CreateRemoteThread($hProcess, 0, 0, $pFreeLibrary, $aModule[$i][0], 0)
If @extended Then $iFlags = 1
_LsaCloseHandle($hThread)
Next
$aModule = _EnumProcessModules($hProcess)
For $i = 1 To $aModule[0][0]
If $aModule[$i][1] = $sModule Then $iFlags = 0
Next
Return SetError(0, _LsaCloseHandle($hProcess), $iFlags)
EndFunc ;==>_UnloadDll
Func _GetFullPathName($sFile)
Local $iResult
$iResult = DllCall("Kernel32.dll", "int", "GetFullPathName", _
"str", $sFile, "dword", 260, "str", "", "str", "")
Return $iResult[3]
EndFunc ;==>_GetFullPathName
Func _GetModuleHandle($sModule)
Local $iResult
$iResult = DllCall("Kernel32.dll", "long", "GetModuleHandle", "str", $sModule)
Return SetError(_GetLastError(), 0, $iResult[0])
EndFunc ;==>_GetModuleHandle
Func _EnumProcessModules($hProcess)
Local $pBuffer, $tBuffer, $iResult, $aResult[1][2]
$iResult = DllCall("Psapi.dll", "int", "EnumProcessModules", "hWnd", $hProcess, _
"ptr", 0, "dword", 0, "dword*", 0)
$pBuffer = _HeapAlloc($iResult[4])
$iResult = DllCall("Psapi.dll", "int", "EnumProcessModules", "hWnd", $hProcess, _
"ptr", $pBuffer, "dword", $iResult[4], "dword*", 0)
$tBuffer = DllStructCreate("hWnd Modules[" & ($iResult[4] / 4) & "]", $pBuffer)
$aResult[0][0] = $iResult[4] / 4
Redim $aResult[$aResult[0][0] + 1][2]
For $i = 1 To $aResult[0][0]
$aResult[$i][0] = DllStructGetData($tBuffer, "Modules", $i)
$aResult[$i][1] = _GetModuleFileNameEx($hProcess, $aResult[$i][0])
Next
_HeapFree($pBuffer)
Return SetError(0, _FreeVariable($tBuffer), $aResult)
EndFunc ;==>_EnumProcessModules
Func _GetModuleFileNameEx($hProcess, $hModule)
Local $iResult
$iResult = DllCall("Psapi.dll", "dword", "GetModuleFileNameEx", "hWnd", $hProcess, _
"hWnd", $hModule, "str", "", "dword", 260)
Return $iResult[3]
EndFunc ;==>_GetModuleFileNameEx
Func _GetProcAddress($hModule, $sProcdure)
Local $iResult
$iResult = DllCall("Kernel32.dll", "hWnd", "GetProcAddress", "hWnd", $hModule, "str", $sProcdure)
Return $iResult[0]
EndFunc ;==>_GetProcAddress
Func _CreateRemoteThread($hProcess, $pThreadSecur, $iStackSize, $pStartAddr, $pParam, $iFlags)
Local $iResult
$iResult = DllCall("Kernel32.dll", "hWnd", "CreateRemoteThread", "hWnd", $hProcess, _
"ptr", $pThreadSecur, "dword", $iStackSize, "ptr", $pStartAddr, _
"ptr", $pParam, "dword", $iFlags, "dword*", 0)
Return SetError(_GetLastError(), $iResult[7], $iResult[0])
EndFunc ;==>_CreateRemoteThread
#cs
Func _UnloadDll($iProcessID, $sModule)
Local $aModule, $hModule, $pFreeLibrary, $hThread, $hProcess
Local $hToken, $aPriv[1][2] = [[$SE_DEBUG_NAME, 2]], $iFlags
$hToken = _SeOpenProcessToken(-1)
_SeAdjustTokenPrivs($hToken, $aPriv)
_SeCloseHandle($hToken)
$hProcess = _SeOpenProcessToken($iProcessID)
If $hProcess < 1 Then Return SetError(@error, 0, 0)
$sModule = _GetFullPathName($sModule)
$hModule = _GetModuleHandle("Kernel32.dll")
$pFreeLibrary = _GetProcAddress($hModule, "FreeLibrary")
$aModule = _EnumProcessModules($hProcess)
For $i = 1 To $aModule[0][0]
;~ If FileGetVersion($aModule[$i][1],'CompanyName') <> 'Microsoft Corporation' Then MsgBox(0, '', $aModule[$i][1])
If $aModule[$i][1] <> $sModule Then ContinueLoop
$hThread = _CreateRemoteThread($hProcess, 0, 0, $pFreeLibrary, $aModule[$i][0], 0)
If @extended Then $iFlags = 1
_SeCloseHandle($hThread)
Next
$aModule = _EnumProcessModules($hProcess)
For $i = 1 To $aModule[0][0]
If $aModule[$i][1] = $sModule Then $iFlags = 0
Next
Return SetError(0, _SeCloseHandle($hProcess), $iFlags)
EndFunc ;==>_UnloadDll
Func _GetFullPathName($sFile)
Local $iResult
$iResult = DllCall("Kernel32.dll", "int", "GetFullPathName", _
"str", $sFile, "dword", 260, "str", "", "str", "")
Return $iResult[3]
EndFunc ;==>_GetFullPathName
Func _GetModuleHandle($sModule)
Local $iResult
$iResult = DllCall("Kernel32.dll", "long", "GetModuleHandle", "str", $sModule)
Return SetError(_SeLastError(), 0, $iResult[0])
EndFunc ;==>_GetModuleHandle
Func _EnumProcessModules($hProcess)
Local $pBuffer, $tBuffer, $iResult, $aResult[1][2]
$iResult = DllCall("Psapi.dll", "int", "EnumProcessModules", "hWnd", $hProcess, _
"ptr", 0, "dword", 0, "dword*", 0)
$pBuffer = _SeHeapAlloc($iResult[4])
$iResult = DllCall("Psapi.dll", "int", "EnumProcessModules", "hWnd", $hProcess, _
"ptr", $pBuffer, "dword", $iResult[4], "dword*", 0)
$tBuffer = DllStructCreate("hWnd Modules[" & ($iResult[4] / 4) & "]", $pBuffer)
$aResult[0][0] = $iResult[4] / 4
ReDim $aResult[$aResult[0][0] + 1][2]
For $i = 1 To $aResult[0][0]
$aResult[$i][0] = DllStructGetData($tBuffer, "Modules", $i)
$aResult[$i][1] = _GetModuleFileNameEx($hProcess, $aResult[$i][0])
Next
_SeHeapFree($pBuffer)
Return SetError(0, _FreeVariable($tBuffer), $aResult)
EndFunc ;==>_EnumProcessModules
Func _FreeVariable(ByRef $vVariable, $vValue = 0, $vReturn = "", $iError = @error, $iExtended = @extended)
$vVariable = $vValue
Return SetError($iError, $iExtended, $vReturn)
EndFunc ;==>_FreeVariable
Func _GetModuleFileNameEx($hProcess, $hModule)
Local $iResult
$iResult = DllCall("Psapi.dll", "dword", "GetModuleFileNameEx", "hWnd", $hProcess, _
"hWnd", $hModule, "str", "", "dword", 260)
Return $iResult[3]
EndFunc ;==>_GetModuleFileNameEx
Func _GetProcAddress($hModule, $sProcdure)
Local $iResult
$iResult = DllCall("Kernel32.dll", "hWnd", "GetProcAddress", "hWnd", $hModule, "str", $sProcdure)
Return $iResult[0]
EndFunc ;==>_GetProcAddress
Func _CreateRemoteThread($hProcess, $pThreadSecur, $iStackSize, $pStartAddr, $pParam, $iFlags)
Local $iResult
$iResult = DllCall("Kernel32.dll", "hWnd", "CreateRemoteThread", "hWnd", $hProcess, _
"ptr", $pThreadSecur, "dword", $iStackSize, "ptr", $pStartAddr, _
"ptr", $pParam, "dword", $iFlags, "dword*", 0)
Return SetError(_SeLastError(), $iResult[7], $iResult[0])
EndFunc ;==>_CreateRemoteThread
#ce
再升级一下!