zoukankan      html  css  js  c++  java
  • [转载]inno setup

    http://bbs.hanzify.org/thread-htm-fid-48.html
    http://bbs.hanzify.org/read-htm-tid-75470.html
    http://bbs.hanzify.org/read-htm-tid-66812-page-1.html

    #define MyAppName "天漏客安装程序"
    #define MyAppVerName "天漏客安装程序 1.0"
    #define MyAppPublisher "天漏客"
    #define MyAppURL "/"
    #define MyAppExeName "MainExe.exe"
    ;注册表卸载信息位置
    #define MyAppRegUninstall "Software\Microsoft\Windows\CurrentVersion\Uninstall\"

    [Setup]
    ; 注: AppId的值为单独标识该应用程序。
    ; 不要为其他安装程序使用相同的AppId值。
    ; (生成新的GUID,点击 工具|在IDE中生成GUID。)
    AppId={{A6286A7F-2B3B-4DAF-99B6-D01774BA0B3E}
    AppName={#MyAppName}

    ;下面这行,安装程序会在运行之前检测互斥量是否存在,从而判断是否已经有程序在运行
    ;根据需要添加。不要忘记了在你的程序中要创建这个互斥量才行。
    ;后面通过程序来检测,这里就不检测了。
    ;AppMutex = MutexBugsky

    ;在添加/删除 控制面板中“支持”信息中显示的内容
    ;具体位置可看:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AppId]
    ;AppId是上面的字符串
    ;也可以手动设置,见[Registry]段注释的部分
    ;带版本号的程序名称
    AppVerName={#MyAppVerName}
    AppPublisher={#MyAppPublisher}
    AppPublisherURL={#MyAppURL}
    AppSupportURL={#MyAppURL}
    AppUpdatesURL={#MyAppURL}

    ;选择安装目标位置的默认目录名
    DefaultDirName={pf}\{#MyAppName}
    ;指定开始菜单目录名
    DefaultGroupName={#MyAppName}
    AllowNoIcons=yes
    LicenseFile=D:\天漏客\版权文件.txt
    InfoBeforeFile=D:\天漏客\安装之前显示的提示信息.txt
    InfoAfterFile=D:\天漏客\安装后显示的信息.txt
    ;编译后的输出路径
    OutputDir=D:\天漏客
    ;编译后输出文件名
    OutputBaseFilename=天漏客
    SetupIconFile=D:\天漏客\MainExe.ico
    Compression=lzma
    SolidCompression=yes

    [Languages]
    ;可根据自己的需要再添加语言包
    ;语言包在inno setup的安装目录language目录下
    Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
    Name: "chinesetrad"; MessagesFile: "compiler:Languages\ChineseTrad.isl"
    Name: "english"; MessagesFile: "compiler:Languages\English.isl"

    [Tasks]
    ;创建桌面图标
    Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
    ;创建快速启动栏
    Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

    [Files]
    ;如果是要注册控件,只需要在Flags标记后面加上: regserver restartreplace
    ;regserver表示注册控件,restartreplace表示如果已存在,那么重启后覆盖。
    Source: "D:\天漏客\MainExe.exe"; DestDir: "{app}"; Flags: ignoreversion
    Source: "D:\天漏客\BeforeInstallEnd.exe"; DestDir: "{app}"; Flags: ignoreversion
    Source: "D:\天漏客\添加的文件夹\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
    ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

    [Icons]
    ;各种图标
    Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
    Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
    Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
    Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

    [Registry]
    ;注册表中添加自启动
    Root: HKLM; Subkey: "software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "bugsky"; ValueData: "{app}\MainExe.exe"; Flags: uninsdeletevalue
    ;注册表中添加自己的程序信息
    Root: HKLM; Subkey: "software\bugsky"; ValueType: string; ValueName: "Install"; ValueData: "{app}"; Flags: uninsdeletevalue

    ;添加下面两行后,通过“运行”命令,可以直接执行你的程序。
    ;如以“bugsky.exe”建立次级键,将其默认值设为程序路径;再在当前键下建立“Path”键,值为程序目录。
    ;好了以后,直接在“运行”中输入“retrieverUser.exe”来执行指定的程序了。
    Root: HKLM; Subkey: "software\Microsoft\Windows\CurrentVersion\App Paths\{#MyAppExeName}";ValueType:string;ValueName:"";ValueData:"{app}\{#MyAppExeName}"; Flags:uninsdeletekey
    Root: HKLM; Subkey: "software\Microsoft\Windows\CurrentVersion\App Paths\{#MyAppExeName}";ValueType:string;ValueName:"Path";ValueData:"{app}";  Flags:uninsdeletekey

    ;在添加/删除 控制面板中“支持”信息中显示的内容
    ;采用自己添加的方式。如果自己添加,注意要指定Flags:uninsdeletekey标志。
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"UninstallString";ValueData:"{app}\unins000.exe" ;  Flags:uninsdeletekey
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"URLInfoAbout";ValueData:"{#MyAppURL}" ;  Flags:uninsdeletekey
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"URLUpdateInfo";ValueData:"{#MyAppURL}" ;  Flags:uninsdeletekey
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"HelpLink";ValueData:"{#MyAppURL}";  Flags:uninsdeletekey
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"Publisher";ValueData:"{#MyAppPublisher}";  Flags:uninsdeletekey
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"InstallLocation";ValueData:"{app}";  Flags:uninsdeletekey
    ;Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}"; ValueType:string;ValueName:"DisplayName";ValueData:"{#MyAppVerName}";  Flags:uninsdeletekey


    [Run]
    ;安装完成之前运行的。后面的标志Flags来区分。
    Filename: "{app}\BeforeInstallEnd.exe"; Description: "设置初始化密码"; Flags: waituntilterminated
    ;安装完成后运行
    Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent

    [UninstallDelete]
    ;可能程序运行后,会创建一些文件,那么在卸载时,要删除,在此处。
    Type: files; Name: "{app}\Retriever.db"

    [code]
    function InitializeSetup():boolean;
    var ResultCode:Integer;
    var bResult:boolean;
    var hwnd:HWND;

    begin
        Result := true;
        //第一步,检测是否有另一个安装程序在运行
        bResult :=  CheckForMutexes('MutexBugskySetup');
        if  bResult = true then
        begin
           MsgBox('另一安装程序已经在运行,此安装程序将退出。',mbInformation,MB_OK);
           Result := false;
           Exit;
        end else
        begin
            //没有就创建互斥量
            CreateMutex('MutexBugskySetup');
        end;

        //第二步,检测程序是否已经安装过
        if RegKeyExists(HKLM,'{#MyAppRegUninstall}{#MyAppExeName}') then
        begin
            //提示用户:是卸载还是继续安装
            ResultCode := MsgBox('安装程序检测到您已经天漏客程序,您是否继续安装?'#13 #10'选择“是”继续安装;选择“否”,退出安装。',mbInformation,MB_YESNO);
            //继续安装
            if ResultCode = IDYES then
            begin
                Result := true;
            end else
            begin
                Result := false;
                Exit;
            end;
         end;

        if RegKeyExists(HKLM,'{#MyAppRegUninstall}{#MyAppExeName}_is1') then
        begin
            //提示用户:是卸载还是继续安装
            ResultCode := MsgBox('安装程序检测到您已经天漏客程序,您是否继续安装?'#13 #10'选择“是”继续安装;选择“否”,退出安装。',mbInformation,MB_YESNO);
            //继续安装
            if ResultCode = IDYES then
            begin
                Result := true;
            end else
            begin
                Result := false;
                Exit;
            end;
         end;


        //先检测进程中服务程序
        //根据窗口的名称或者类名来查找,我这里根据窗口名称吧
        //hwnd := FindWindowByClassName('ClassName');
        hwnd := FindWindowByWindowName('主运行程序');
        while  (hwnd <> 0) do
        begin
            ResultCode := MsgBox('安装程序检测到系统中正运行天漏客程序,将关闭程序后安装。'#13 #10'选择“是”,安装程序自动关闭服务程序; '#13 #10'选择“否”,退出安装程序,自行关闭服务程序后再试。',mbInformation,MB_YESNO);
            if ResultCode = IDYES then
            begin
                //发送关闭消息
                PostMessage(hwnd,18,0,0);  //18为WM_QUIT消息
                Sleep(100);
                Result := true;
                hwnd := FindWindowByWindowName('主运行程序');

            end else
            begin
                //退出
                hwnd := 0;
                Result := false;
                Exit;
            end;
         end;

    end;

    /////////////////////////////////////////////////////////////////////////////////////////


    //////////////////////////////////////////////////////////////////////////
    procedure CurUninstallStepChanged (CurUninstallStep: TUninstallStep );
    var ResultCode:Integer;
    var bResult:boolean;
    var hwnd:HWND;
    var CloseNum:integer;
    begin
        case CurUninstallStep of
        //确定下载之后,在确认“您是否真的卸载软件”之后/////////////////////////////////////////
        usAppMutexCheck:
        begin
            MsgBox('现在开始卸载,先检测主运行程序是否在运行。如果在运行会自动关闭。',mbInformation,MB_OK);
            //先检测进程中程序是否在运行
            hwnd := FindWindowByWindowName('主运行程序');
            CloseNum := 0;
            while  ((hwnd <> 0) and (CloseNum < 5)) do
            begin
                //关闭服务程序,尝试5次。
                PostMessage(hwnd,18,0,0);
                Sleep(100);
                CloseNum := CloseNum + 1;
                hwnd := FindWindowByWindowName('主运行程序');
            end;

        end;
        //开始卸载,之后就要进行卸载,显示滚动条了。////////////////////////////////
        usUninstall:
        begin
              //注销组件
              //UnregisterServer(false,ExpandConstant('{app}\控件名称.ocx') ,true);
              //DeleteFile(ExpandConstant('{app}\控件名称.ocx'));
              MsgBox('现在正在卸载!',mbInformation,MB_OK);
        end;
        //卸载完成,滚动条结束,点击“确定”之后/////////////////////////////////////
        usPostUninstall:
        begin
             MsgBox('现在卸载工作完成!',mbInformation,MB_OK);
        end;
        //成功卸载之后,弹出“成功卸载”对话框之后////////////////////////////////
        usDone:
        begin
              MsgBox('全部完成,现在你可以设定一下其他要运行的功能,比如打开某个链接。',mbInformation,MB_OK);
              //可以做一些,比如打开网页调查表(用户为什么卸载软件,像迅雷一样)
        end;
    end;
    end;

  • 相关阅读:
    用UltraISO制作U盘启动盘及设BIOS从U盘启动的方法
    Android 超链接 打开网址
    ActionScript常用正则表达式收集
    Android模拟器安装,使用APK文件
    正则表达式的规则
    WORD的批注
    机械迷城 迷宫全图
    mysql新建用户及授权
    验证IP是否合法
    ThinkPad水货靠谱店
  • 原文地址:https://www.cnblogs.com/fx2008/p/2375102.html
Copyright © 2011-2022 走看看