Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

安装前无法自动卸载 #1

Open
mathcoder23 opened this issue Dec 21, 2017 · 1 comment
Open

安装前无法自动卸载 #1

mathcoder23 opened this issue Dec 21, 2017 · 1 comment

Comments

@mathcoder23
Copy link

说明

在InitializeSetup中有执行卸载的程序,但无法生效,原因是卸载的代码放在了while 判断运行中的循环中,如果没有运行中程序将不会执行卸载程序。

//修改前
function InitializeSetup():boolean;
var
   IsAppRunning: boolean;
   IsAppRunning1: boolean;
    ResultStr: String;
  ResultCode: Integer;
begin
    Result := true;
// 第二步,安装时判断客户端是否正在运行
   begin
    Result:= true;//安装程序继续
    IsAppRunning:= IsModuleLoaded('YNote.exe');
    IsAppRunning1:= IsModuleLoaded('YNote_1.exe');
    while IsAppRunning or IsAppRunning1 do
       begin
        if MsgBox('Detects that "YNote" or "YNote_1" is running' #13#13 'You must close it first and then click "OK" to continue the installation, or you can "Cancel" out!', mbConfirmation, MB_OKCANCEL) = IDOK then
         begin
         IsAppRunning:= IsModuleLoaded('YNote.exe')
         IsAppRunning1:= IsModuleLoaded('YNote_1.exe');
           //if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}_is1', 'UninstallString', ResultStr) then
    begin
      ResultStr := RemoveQuotes(ResultStr);
      Exec(ResultStr, '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
    end
    result := true;
         end else begin
         IsAppRunning:= false;
         Result:= false;//安装程序退出
         Exit;
         end;
       end;
     end;
end;

//修改后
function InitializeSetup():boolean;
var
   IsAppRunning: boolean;
   IsAppRunning1: boolean;
    ResultStr: String;
  ResultCode: Integer;
begin
    Result := true;
// 第二步,安装时判断客户端是否正在运行
   begin
    Result:= true;//安装程序继续
    IsAppRunning:= IsModuleLoaded('{#MyAppProcessName}.exe');
    IsAppRunning1:= IsModuleLoaded('{#MyAppProcessName}_1.exe');
    while IsAppRunning or IsAppRunning1 do
       begin
        if MsgBox('九狐-云电销应用程序正在运行,请先关闭程序后安装', mbConfirmation, MB_OKCANCEL) = IDOK then
         begin
         IsAppRunning:= IsModuleLoaded('{#MyAppProcessName}.exe')
         IsAppRunning1:= IsModuleLoaded('{#MyAppProcessName}_1.exe');
         
         end else begin
         IsAppRunning:= false;
         Result:= false;//安装程序退出
         Exit;
         end;
       end;
     end;
     if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}_is1', 'UninstallString', ResultStr) then
      begin
       
        ResultStr := RemoveQuotes(ResultStr);
        Exec(ResultStr, '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
        if ResultCode = 1 then
        begin
           IsAppRunning:= false;
           Result:= false;//安装程序退出
           Exit;
        end;
       
      end

      result := true;
     
end;

关于应用程序名也做了修改。

@GanZhiXiong
Copy link
Owner

安装包没有添加这个功能,原因是一般的应用程序安装包都是替换安装,不需要用户先卸载之前的版本,该安装包脚本也是如此。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants