2014-05-13 29 views
0

我試圖創建一個安裝程序來檢查當前的傳輸控制協議連接在windows64機器。是否有可能創建?inno setup:如何在windows中獲取tcp連接列表?

我打算使用使用extern的命令行。如果我給ls -lf它會返回所有當前運行的文件

[code] 
const 
GetFileExInfoStandard = $0; 

type 
FILETIME = record 
LowDateTime: DWORD; 
HighDateTime: DWORD; 
end; 
WIN32_FILE_ATTRIBUTE_DATA = record 
FileAttributes: DWORD; 
CreationTime: FILETIME; 
LastAccessTime: FILETIME; 
LastWriteTime: FILETIME; 
    FileSizeHigh: DWORD; 
    FileSizeLow: DWORD; 
end; 

SYSTEMTIME = record 
    Year:   WORD; 
    Month:  WORD; 
    DayOfWeek: WORD; 
    Day:   WORD; 
    Hour:   WORD; 
    Minute:  WORD; 
    Second:  WORD; 
    Milliseconds: WORD; 
end; 

function GetFileAttributesEx ( 
    FileName:    string; 
    InfoLevelId:   DWORD; 
    var FileInformation: WIN32_FILE_ATTRIBUTE_DATA 
): Boolean; 
external '[email protected] stdcall'; 

function FileTimeToSystemTime(
    FileTime:   FILETIME; 
    var SystemTime:  SYSTEMTIME 
): Boolean; 
external '[email protected] stdcall'; 
var 
TmpfileName: String; 
i,j,ResultCode:integer; 
ExecStdout,processes:Tarrayofstring; 
Page:TInputOptionWizardPage; 

procedure initializeWizard; 
begin 
    TmpFileName := ExpandConstant('{tmp}') + '\processes.txt'; 
    Exec('cmd.exe','/C netstat > "' + TmpFileName + '"', 
    '',SW_HIDE,ewWaitUntilTerminated, ResultCode); 
    Page := CreateInputOptionPage(wpWelcome, 
    'Current Running processes on your  computer', 
    'Displays All Running processes on this machine, selecte any process 
    to terminate','Seleet Any one from the list, Click on next'+#13+ 
    'Note: Do not select System processes this may cause damage to your machine..' 
    , True, True); 
    end; 

function NextButtonClick(CurPageID: Integer): Boolean; 
begin 
if CurPageID = wpwelcome then 
begin 
if LoadStringsFromFile(TmpFileName, ExecStdout) then 
     begin 
     for i:=3 to GetArrayLength(ExecStdout)-1 do 
     begin 
     setarraylength(processes,i-2) 
      processes[i-3]:=''; 
     for j:=1 to length(Execstdout[i]) do 
      begin 
      if not ((Execstdout[i][j]=' ') and (Execstdout[i][j+1]=' ')) then 
       begin 
       processes[i-3]:=processes[i-3]+execstdout[i][j]; 
       end; 
       if ((Execstdout[i][j]=' ') and (Execstdout[i][j+1]=' ')) then 
       j:=length(Execstdout[i]); 

      end; 
      page.add(processes[i-3]); 
     end; 
     end; 

Result:=true; 
end; 
if CurPageID = page.id then 
begin 
result:=true; 
end; 
    if CurPageID = wpReady then 
Result:=true; 

end;

+0

您面臨的問題是什麼? – tod

+0

你能告訴我什麼是我需要使用此功能 – Ramkee

+0

我會使用['GetTcpTable'](http://msdn.microsoft.com/en-us/library/windows/desktop/aa366026( v = vs.85).aspx)函數。 – TLama

回答

0

此代碼完美工作,但可能需要半分鐘才能顯示結果。

[Code] 

function NextButtonClick(CurPage: Integer): Boolean; 
var 
    TmpFileName, ExecStdout: string; 
    ResultCode: integer; 
begin 
    if CurPage = wpWelcome then begin 
    TmpFileName := ExpandConstant('{tmp}') + '\ipconfig_results.txt'; 
    Exec('cmd.exe', '/C netstat > "' + TmpFileName + '"', '', SW_HIDE, 
      ewWaitUntilTerminated, ResultCode); 
if LoadStringFromFile(TmpFileName, ExecStdout) then begin 

     MsgBox(ExecStdout, mbInformation, MB_OK); 
     // do something with contents of file... 
    end; 
    DeleteFile(TmpFileName); 
    end; 
    Result := True; 
end; 
相關問題