7

inno setup を使い始めたばかりですが、うまく機能しているようです。ただし、アプリが既にインストールされている状態でインストーラーを実行すると、再インストールされます。ユーザーにアンインストールを許可したいと思います。これは可能ですか?可能であれば、どのように行うことができますか?

具体的には、宿題のためにゲームを書きました。inno setup を使用してインストーラーを作成しました。アプリは正常にインストールされ、コントロール パネルを使用してアンインストールできますが、私の教授は、インストーラーを再実行してアンインストール オプションを選択することで、アプリケーションをアンインストールできるようにしたいと考えています。マークするこれらの割り当てが約 50 あるので、これで時間を節約できます。

ありがとう、

ジェリー

4

3 に答える 3

13

次のスクリプトは、セットアップの開始時にアプリケーションがターゲット システムに既にインストールされている場合、次のオプション フォームを作成します。

ここに画像の説明を入力

ユーザーがRepairボタンをクリックすると、セットアップが正常に開始されます。ユーザーがUninstallボタンをクリックすると、以前にインストールされたアプリケーションがアンインストールされます。ユーザーがそのフォームを閉じると、何も起こりません。

AppIdスクリプトは次のとおりです (スクリプトの setup ディレクティブに一意の値を指定することを忘れないでください)。

[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, RegKey, 'UninstallString', 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;
于 2013-01-22T02:27:24.433 に答える
3

何らかの理由であなたのコード

RegKey := Format('%s\%s_is1', ['Software\Microsoft\Windows\CurrentVersion\Uninstall', 
    '{#emit SetupSetting("AppId")}']);

余分な { を _is1 値に返しました。実装のどこが間違っていたのか、またはどこが間違っていたのかを確認する時間がありませんでした。確認したのは、インストーラーが

RegKey := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');

代わりの。

それが役に立てば幸い。

コードサンプルありがとうございます。

于 2013-06-28T12:29:32.060 に答える
1

Inno Setup を使用する場合、以前のバージョンが別のインストーラー プログラムによってインストールされていない限り、以前のバージョンをアンインストールする必要はありません。それ以外の場合、アップグレードは自動的に処理されます。

あなたの答えはここにあります:

InnoSetup: 以前にインストールされたバージョンを自動的にアンインストールする方法は? 以前にインストールされたバージョン

于 2013-01-21T20:58:48.263 に答える