Local $port_list = @ScriptDir & '\port_list.txt'
RunWait(@ComSpec & " /c " & 'netstat -ano >' & $port_list, '', @SW_HIDE)
Local $file = FileOpen($port_list)
If $file <> -1 Then
While 1
Local $line = FileReadLine($file)
If @error = -1 Then ExitLoop
If StringInStr($line, ':80') Then
Local $aArray = StringSplit($line, Chr(32))
MsgBox(4096, '发现占用端口80程序:', _GetProcPath($aArray[$aArray[0]]))
EndIf
WEnd
EndIf
FileClose($file)
Func _GetProcPath($iPID)
Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', 0x00000410, 'int', 0, 'int', $iPID)
If $aProc[0] = 0 Then Return SetError(1, 0, '')
Local $vStruct = DllStructCreate('int[1024]')
DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', _
DllStructGetSize($vStruct), 'int_ptr', 0)
Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', _
DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
Return $aReturn[3]
EndFunc ;==>_GetProcPath
|