c/c++ 软件集成 安装和可卸载软件
作为一个工程师应具备的一些能力:
1. 首先具备这款软件:
>inno Setup 免费版还开源,良心货,妥妥的。
2. 这款软件上手也比较款,可自行参考使用文档
3.编译成功,生成代码之后,样子可能如下:
1 ; Script generated by the Inno Setup Script Wizard. 2 ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! 3 4 #define MyAppName "My Program" 5 #define MyAppVersion "beta 1.0" 6 #define MyAppPublisher "精灵球网络科技有限公司, Inc." 7 #define MyAppURL "http://www.cnblogs.com/gongxijun/" 8 #define MyAppExeName "startup.bat" 9 10 [Setup] 11 ; NOTE: The value of AppId uniquely identifies this application. 12 ; Do not use the same AppId value in installers for other applications. 13 ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) 14 AppId={{FA1B17D2-4CC5-465E-9A5F-DCA022B6EA1A} 15 AppName={#MyAppName} 16 AppVersion={#MyAppVersion} 17 ;AppVerName={#MyAppName} {#MyAppVersion} 18 AppPublisher={#MyAppPublisher} 19 AppPublisherURL={#MyAppURL} 20 AppSupportURL={#MyAppURL} 21 AppUpdatesURL={#MyAppURL} 22 DefaultDirName={pf}\{#MyAppName} 23 DefaultGroupName={#MyAppName} 24 AllowNoIcons=yes 25 OutputDir=D:\Users\gxj\Desktop\TFriend 26 OutputBaseFilename=setup 27 Compression=lzma 28 SolidCompression=yes 29 30 [Languages] 31 Name: "english"; MessagesFile: "compiler:Default.isl" 32 Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" 33 Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl" 34 Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl" 35 Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl" 36 Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl" 37 Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl" 38 Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl" 39 Name: "french"; MessagesFile: "compiler:Languages\French.isl" 40 Name: "german"; MessagesFile: "compiler:Languages\German.isl" 41 Name: "greek"; MessagesFile: "compiler:Languages\Greek.isl" 42 Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl" 43 Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl" 44 Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl" 45 Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" 46 Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl" 47 Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl" 48 Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl" 49 Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl" 50 Name: "scottishgaelic"; MessagesFile: "compiler:Languages\ScottishGaelic.isl" 51 Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl" 52 Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl" 53 Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl" 54 Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl" 55 Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl" 56 Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl" 57 58 [Tasks] 59 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked 60 Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1 61 62 [Files] 63 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\startup.bat"; DestDir: "{app}"; Flags: ignoreversion 64 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\2005_x64.exe"; DestDir: "{app}"; Flags: ignoreversion 65 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\2008_x64.exe"; DestDir: "{app}"; Flags: ignoreversion 66 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\2010_IA64.exe"; DestDir: "{app}"; Flags: ignoreversion 67 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\2012_x64.exe"; DestDir: "{app}"; Flags: ignoreversion 68 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\2013_x64.exe"; DestDir: "{app}"; Flags: ignoreversion 69 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\2014_x64.exe"; DestDir: "{app}"; Flags: ignoreversion 70 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\cmd5.obj"; DestDir: "{app}"; Flags: ignoreversion 71 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\explorer1.obj"; DestDir: "{app}"; Flags: ignoreversion 72 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\GetSysInfo.obj"; DestDir: "{app}"; Flags: ignoreversion 73 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\GoodInf.obj"; DestDir: "{app}"; Flags: ignoreversion 74 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\jietu.obj"; DestDir: "{app}"; Flags: ignoreversion 75 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\json_reader.asm"; DestDir: "{app}"; Flags: ignoreversion 76 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\json_value.asm"; DestDir: "{app}"; Flags: ignoreversion 77 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\json_writer.asm"; DestDir: "{app}"; Flags: ignoreversion 78 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\Kehu.Build.CppClean.log"; DestDir: "{app}"; Flags: ignoreversion 79 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\Kehu.exe"; DestDir: "{app}"; Flags: ignoreversion 80 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\Kehu.log"; DestDir: "{app}"; Flags: ignoreversion 81 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\Kehu.obj"; DestDir: "{app}"; Flags: ignoreversion 82 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\Kehu.res"; DestDir: "{app}"; Flags: ignoreversion 83 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\KehuDlg.obj"; DestDir: "{app}"; Flags: ignoreversion 84 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\libmysql.dll"; DestDir: "{app}"; Flags: ignoreversion 85 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\MainMenu.obj"; DestDir: "{app}"; Flags: ignoreversion 86 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\MyTracker.obj"; DestDir: "{app}"; Flags: ignoreversion 87 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\News.obj"; DestDir: "{app}"; Flags: ignoreversion 88 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\ScreepJieTu.obj"; DestDir: "{app}"; Flags: ignoreversion 89 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\startup.bat"; DestDir: "{app}"; Flags: ignoreversion 90 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\stdafx.obj"; DestDir: "{app}"; Flags: ignoreversion 91 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\vc120.pdb"; DestDir: "{app}"; Flags: ignoreversion 92 Source: "C:\Data\TFriend\RT\Kehu\x64\Release\WMI_DeviceQuery.obj"; DestDir: "{app}"; Flags: ignoreversion 93 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files 94 95 [Icons] 96 Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" 97 Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}" 98 Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" 99 Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon 100 Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon 101 102 [Run] 103 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: shellexec postinstall skipifsilent
3. 在集成的时候,有时,如果有特殊的条件需要集成运行库,那就得写下如下的批处理文件,并将要集成的运行库下载放到打包文件中,然后参考如下文件:
1 @echo off 2 ::::::查询微软软件当前的注册表 3 set "HKLMU=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 4 reg query %HKLMU%\{6E8E85E8-CE4B-4FF5-91F7-04999C9FAE6A}>nul 2>nul&&set VC2005=Microsoft Visual C++ 2005 Redistributable X64 5 reg query %HKLMU%\{071C9B48-7C32-4621-A0AC-3F809523288F}>nul 2>nul&&set VC2005=Microsoft Visual C++ 2005 SP1 Redistributable X64 6 reg query %HKLMU%\{6CE5BAE9-D3CA-4B99-891A-1DC6C118A5FC}>nul 2>nul&&set VC2005=Microsoft Visual C++ 2005 SP1 Redistributable ATL Security Update X64 7 reg query %HKLMU%\{03ED71EA-F531-4927-AABD-1C31BCE8E187}>nul 2>nul&&set VC2005=Microsoft Visual C++ 2005 Redistributable IA64 8 reg query %HKLMU%\{0F8FB34E-675E-42ED-850B-29D98C2ECE08}>nul 2>nul&&set VC2005=Microsoft Visual C++ 2005 SP1 Redistributable IA64 9 reg query %HKLMU%\{85025851-A784-46D8-950D-05CB3CA43A13}>nul 2>nul&&set VC2005=Microsoft Visual C++ 2005 SP1 Redistributable ATL Security Update IA64 10 11 if defined VC2005 (echo %VC2005% 已安装!&ping -n 5 127.1>nul) else (goto VC2005) 12 13 :VC2005Install 14 @echo on 15 @echo 安装运行中.....请耐心等待! 16 :::::将运行库放置打包到和需要支持的软件一起 17 @if exist 2005_x64.exe (echo 开始安装..... &start 2005_x64.exe &ping -n 10 127.1 >nul) else (echo 没有找到安装包!请自己下载VC2005并按照 &goto QVC2008) 18 19 :QVC2008 20 set "HKLMU=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 21 reg query %HKLMU%\{350AA351-21FA-3270-8B7A-835434E766AD}>nul 2>nul&&set VC2008=Microsoft Visual C++ 2008 Redistributable X64 22 reg query %HKLMU%\{8220EEFE-38CD-377E-8595-13398D740ACE}>nul 2>nul&&set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable X64 23 reg query %HKLMU%\{4B6C7001-C7D6-3710-913E-5BC23FCE91E6}>nul 2>nul&&set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable ATL Security Update X64 24 reg query %HKLMU%\{2B547B43-DB50-3139-9EBE-37D419E0F5FA}>nul 2>nul&&set VC2008=Microsoft Visual C++ 2008 Redistributable IA64 25 reg query %HKLMU%\{5827ECE1-AEB0-328E-B813-6FC68622C1F9}>nul 2>nul&&set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable IA64 26 reg query %HKLMU%\{977AD349-C2A8-39DD-9273-285C08987C7B}>nul 2>nul&&set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable ATL Security Update IA64 27 28 if defined VC2008 (echo %VC2008% 已安装!&ping -n 5 127.1>nul) else (goto VC2008) 29 @if exist 2008_x64.exe (echo 开始安装..... &start 2008_x64.exe &ping -n 10 127.1 >nul) else (echo 没有找到安装包!请自己下载VC2005并按照 &goto QVC2010) 30 31 :QVC2010 32 @if exist 2010_IA64 (start 2010_IA64.exe) else goto CC 33 @echo 开始安装..... 34 @ping -n 10 127.1 >nul 35 :CC 36 @if exist 2012_x64.exe (start 2012_x64.exe) else goto DD 37 @echo 开始安装..... 38 @ping -n 10 127.1 >nul 39 :DD 40 @if exist 2013_x64.exe (start 2013_x64.exe) else goto EE 41 @echo 开始安装..... 42 @ping -n 10 127.1 >nul 43 44 :EE 45 @if exist 2014_x64.exe (start 2014_x64.exe) else goto FF 46 @echo 开始安装..... 47 @ping -n 10 127.1 >nul 48 49 :FF 50 @if exist Kehu.exe (start Kehu.exe) else echo 安装失败,请重新安装 51 @echo 按任意键结束......... 52 pause 53 @echo off
这样之后,当你点击生成的软件之后,它就会像我们以前首先的软件一样,成为一款正规的软件,具备安转,卸载,注册,以及自动检测运行库是否安装,并自动安装的软件了!!!
编程是一种快乐,享受代码带给我的乐趣!!!