inno steup 安装判断 进程是否运行

1、添加了卸载判断用语
2、添加了安装程序进程是否存在使用了wmi服务

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "陕十三1.0"
#define MyAppVersion "1.0"
#define MyAppPublisher ""
#define MyAppExeName "陕十三.exe"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。)
AppId=
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={autopf}Expert_acquisition_system_v1
DisableProgramGroupPage=yes
; 以下行取消注释,以在非管理安装模式下运行(仅为当前用户安装)。
;PrivilegesRequired=lowest
DefaultGroupName=陕十三2.0
OutputBaseFilename=陕十三1.0
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"


[code]
function IsAppRunning(const FileName : string): Boolean;
var
    FSWbemLocator: Variant;
    FWMIService   : Variant;
    FWbemObjectSet: Variant;
begin
    Result := false;
    FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
    FWMIService := FSWbemLocator.ConnectServer('', 'rootCIMV2', '', '');
    FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
    Result := (FWbemObjectSet.Count > 0);
    FWbemObjectSet := Unassigned;
    FWMIService := Unassigned;
    FSWbemLocator := Unassigned;
end;

function InitializeSetup(): Boolean;
begin
 Result := IsAppRunning('mysqld.exe');
  if Result then
  begin
      MsgBox('当前系统中已经存在数据库,请先关闭程序后再重试! ', mbError, MB_OK); 
    result:=false;
end
else
    begin
      result := true;
    end;
  end;

 function InitializeUninstall(): Boolean;
var
  Text: string;
begin
 
   Result := (MsgBox('当前卸载会卸载所关联的数据库数据以及程序,如继续卸载请按【是】放弃请按【否】', mbConfirmation, MB_YESNO) = IDYES);
end;
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
;Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "E:clientstudent_shengtingmoegovmoegovinRelease陕十三.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:clientstudent_shengtingmoegovmoegovinRelease*"; DestDir: "{app}"; Flags: ignoreversion  recursesubdirs createallsubdirs
Source: "D:
wasexcel导入导出版本install.bat"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:
wasexcel导入导出版本zfxm_rss.sql"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:mysqls	estmysql-5.6.45-winx64*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Icons]
;Name: "{commonprograms}{#MyAppName}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; WorkingDir: {app};
;Name: {commonprograms}{#MyAppName}卸载 {#MyAppName}; Filename:{uninstallexe}; WorkingDir: {app};
;Name: {commonprograms}{#MyAppName}卸载 {#MyAppName}; Filename:{uninstallexe}; WorkingDir: {app};
;Name: "{autodesktop}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks: desktopicon



//开始菜单快捷方式
Name: "{commonprograms}{#MyAppName}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; WorkingDir: {app};

//桌面快捷方式
Name: "{commondesktop}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks: desktopicon
//开始菜单卸载程序
Name: {commonprograms}{#MyAppName}卸载 {#MyAppName}; Filename:{uninstallexe}; WorkingDir: {app};
Name: {commonprograms}{#MyAppName}卸载 {#MyAppName}; Filename:{uninstallexe}; WorkingDir: {app};
   
   
[INI]
;修改数据库配置文件                                
Filename:"{app}my.ini";Section:"client";Key:"port"; String:"3306"                    
;Filename:"{app}my.ini";Section:"client";Key:"default-character-set"; String:"utf8"      gb2312
Filename:"{app}my.ini";Section:"client";Key:"default-character-set"; String:"utf8"      
Filename:"{app}my.ini";Section:"mysql";Key:"port"; String:"3306"   
;Filename:"{app}my.ini";Section:"mysql";Key:"default-character-set"; String:"utf8" 
Filename:"{app}my.ini";Section:"mysql";Key:"default-character-set"; String:"utf8"  
Filename:"{app}my.ini";Section:"mysqld";Key:"port"; String:"3306"
Filename:"{app}my.ini";Section:"mysqld";Key:"basedir"; String:"{app}"         
Filename:"{app}my.ini";Section:"mysqld";Key:"datadir"; String:"{app}data"             
;Filename:"{app}my.ini";Section:"mysqld";Key:"character-set-server"; String:"utf8"   
Filename:"{app}my.ini";Section:"mysqld";Key:"character-set-server"; String:"gb2312"      
Filename:"{app}my.ini";Section:"mysqld";Key:"default-storage-engine"; String:"InnoDB"       
Filename:"{app}my.ini";Section:"mysqld";Key:"max_connections"; String:"100"     
Filename:"{app}my.ini";Section:"mysqld";Key:"sql_mode"; String:"NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES" 

[Run]             
Filename: "{app}{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent      
;Filename: "{app}vcredist_x64.exe";
Filename: "{app}install.bat";Description:"正在启动或配置相关程序"
[UninstallRun]
Filename: "{app}uninstall.bat";
[UninstallDelete]
Type:filesandordirs;Name:"{app}"



原文地址:https://www.cnblogs.com/mengluo/p/13403211.html