Close running version of program before installing update (Inno Setup)

前端 未结 10 1247
囚心锁ツ
囚心锁ツ 2020-12-23 12:24

This should be simple, I need to stop any previous version of my program from running when the installer starts.

Most people suggested making an exe wh

10条回答
  •  心在旅途
    2020-12-23 13:11

    I have had success using WMIC :

    procedure CurStepChanged(CurStep: TSetupStep);
    var
        ResultCode: Integer;
        wmicommand: string;
    begin
        // before installing any file
        if CurStep = ssInstall then
        begin
            wmicommand := ExpandConstant('PROCESS WHERE "ExecutablePath like ''{app}\%%''" DELETE');
    
            // WMIC "like" expects escaped backslashes
            StringChangeEx(wmicommand, '\', '\\', True);
    
            // you can/should add an "if" around this and check the ResultCode
            Exec('WMIC', wmicommand, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
        end;
    end;
    

    You can also do it in the InitializeSetup but if you do, keep in mind you don't have yet access to the {app} constant. My program doesn't ask for install path, but yours might.

提交回复
热议问题