inno setup 判斷系統有沒有運行的程序函數

 

[Code]
//#############################IsNotProcessRun函數###################################
// 自定義函數,判斷軟件是否運行,參數爲需要判斷的軟件的exe名稱
//系統運行strExeName這個exe,返回真,否則返回false
function IsNotProcessRun(strExeName: String): Boolean;
// 變量定義
var ErrorCode: Integer;
var bRes: Boolean;
var strFileContent: AnsiString;
var strTmpPath: String;  // 臨時目錄
var strTmpFile: String;  // 臨時文件,保存查找軟件數據結果
var strCmdFind: String;  // 查找軟件命令
begin
  strTmpPath := GetTempDir();
  strTmpFile := Format('%sfindSoftRes.txt', [strTmpPath]);
  strCmdFind := Format('/c tasklist /nh|find /c /i "%s" > "%s"', [strExeName, strTmpFile]);
  bRes := ShellExec('open', ExpandConstant('{cmd}'), strCmdFind, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);  
  bRes := LoadStringFromFile(strTmpFile, strFileContent);
  strFileContent := Trim(strFileContent);
  if StrToInt(strFileContent)   > 0 then begin
    result:=true;
    end else result:=false;
  end;
//#############################IsNotProcessRun函數###################################
procedure InitializeWizard();
begin
    if IsNotProcessRun('httpd.exe') then begin
     MsgBox('httpd正在運行', mbInformation, MB_OK);
     end else
     MsgBox('httpd沒有運行', mbInformation, MB_OK);
end;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章