我刚刚开始使用inno设置,它似乎运作良好.但是,当我在安装了应用程序的情况下运行安装程序时,重新安装.我想让用户卸载.这是可能的,如果是这样,怎么办?
具体来说,我为家庭作业写了一个游戏.我使用inno setup制作了一个安装程序.该应用程序安装正常,可以使用控制面板卸载,但我的教授希望能够通过重新运行安装程序并选择卸载选项来卸载该应用程序.这将节省他的时间,因为他有大约50个这样的任务来标记.
谢谢,
格里
解决方法
当安装程序启动时,当目标系统上已安装应用程序时,下一个脚本将生成以下选项:
当用户单击“修复”按钮时,通常会启动设置.当用户单击“卸载”按钮时,将卸载以前安装的应用程序.当用户关闭该表单时,没有任何反应.
这是脚本(不要忘记为脚本中的AppId
安装指令指定,理想情况下是一些唯一的值):
[Setup] AppName=My Program AppVersion=1.5 AppId=1C9FAC66-219F-445B-8863-20DEAF8BB5CC DefaultDirName={pf}\My Program OutputDir=userdocs:Inno Setup Examples Output [CustomMessages] OptionsFormCaption=Setup options... RepairButtonCaption=Repair UninstallButtonCaption=Uninstall [Code] const mrRepair = 100; mrUninstall = 101; function ShowOptionsForm: TModalResult; var OptionsForm: TSetupForm; RepairButton: TNewButton; UninstallButton: TNewButton; begin Result := mrNone; OptionsForm := CreateCustomForm; try OptionsForm.Width := 220; OptionsForm.Caption := ExpandConstant('{cm:OptionsFormCaption}'); OptionsForm.Position := poScreenCenter; RepairButton := TNewButton.Create(OptionsForm); RepairButton.Parent := OptionsForm; RepairButton.Left := 8; RepairButton.Top := 8; RepairButton.Width := OptionsForm.ClientWidth - 16; RepairButton.Caption := ExpandConstant('{cm:RepairButtonCaption}'); RepairButton.ModalResult := mrRepair; UninstallButton := TNewButton.Create(OptionsForm); UninstallButton.Parent := OptionsForm; UninstallButton.Left := 8; UninstallButton.Top := RepairButton.Top + RepairButton.Height + 8; UninstallButton.Width := OptionsForm.ClientWidth - 16; UninstallButton.Caption := ExpandConstant('{cm:UninstallButtonCaption}'); UninstallButton.ModalResult := mrUninstall; OptionsForm.ClientHeight := RepairButton.Height + UninstallButton.Height + 24; Result := OptionsForm.ShowModal; finally OptionsForm.Free; end; end; function GetUninstallerPath: string; var RegKey: string; begin Result := ''; RegKey := Format('%s\%s_is1',['Software\Microsoft\Windows\CurrentVersion\Uninstall','{#emit SetupSetting("AppId")}']); if not RegQueryStringValue(HKEY_LOCAL_MACHINE,RegKey,'UninstallString',Result) then RegQueryStringValue(HKEY_CURRENT_USER,Result); end; function InitializeSetup: Boolean; var UninstPath: string; ResultCode: Integer; begin Result := True; UninstPath := RemoveQuotes(GetUninstallerPath); if UninstPath <> '' then begin case ShowOptionsForm of mrRepair: Result := True; mrUninstall: begin Result := False; if not Exec(UninstPath,'',SW_SHOW,ewNoWait,ResultCode) then MsgBox(FmtMessage(SetupMessage(msgUninstallOpenError),[UninstPath]),mbError,MB_OK); end; else Result := False; end; end; end;