setup.iss 文件
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "appName"
#define MyAppVersion "1.5"
#define MyAppPublisher "appName"
#define MyAppURL "http://localhost:8080/"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{4E3DA5F2-1CB1-450D-953B-F26A3DEG0030}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=appName_V1.5_INS
;SetupIconFile=D:\testexe\favicon.ico
Compression=lzma
SolidCompression=yes
;yes自定义卸载过程
Uninstallable=yes
;自定义默认安装目录
DefaultDirName=C:\{#MyAppName}
;禁止选择安装目录
DisableDirPage=yes
DisableProgramGroupPage=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
Source: "D:\testexe\environment\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Run]
Filename: "{app}\environment.bat";
[Registry]
;将安装路径写入注册表
Root: HKCU; Subkey: "SOFTWARE\appName\config"; Flags: createvalueifdoesntexist
Root: HKCU; Subkey: "SOFTWARE\appName\config"; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "SOFTWARE\appName\config"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: HKCU; Subkey: "SOFTWARE\appName\config"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppVersion}"
Root: HKCU; Subkey: "SOFTWARE\appName\config"; ValueType: dword; ValueName: "VersionNum"; ValueData: "105"
Root: HKCU; Subkey: "SOFTWARE\appName\config"; ValueType: string; ValueName: "Release Date"; ValueData: "2024/05/24"
[Code]
//卸载时执行
function InitializeUninstall(): Boolean;
var
ResultCode: Integer;
BatchFileName: String;
BatchFilePath: String;
begin
BatchFileName := 'unins.bat';
BatchFilePath := ExpandConstant('{app}') + '\' + BatchFileName;
Exec(ExpandConstant('{cmd}'), '/c' + BatchFilePath, '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
Result := True;
end;
//初始化时执行
function InitializeSetup(): Boolean;
var
Version: string;
strPath: string;
ResultCode: Integer;
begin
Result:= TRUE;
//read the version
if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\appName\config', 'Version', Version) then
begin
// Successfully read the value
Version := '检测到已经安装了软件,请勿重复安装';
MsgBox(Version, mbConfirmation, MB_OK)
Result:= FALSE;
end;
end;
environment.bat 文件
@echo off
echo current path: %cd%
echo set var value
set tomcatpath=%cd%\apache-tomcat-7.0.35
set jdkpath=%cd%\jdk1.7.0_80
set jrepath=%cd%\jdk1.7.0_80\jre
echo tomcat path: %tomcatpath%
echo write var value
C:\Windows\System32\setx JAVA_HOME "%jdkpath%" -m
C:\Windows\System32\setx JRE_HOME "%jrepath%" -m
C:\Windows\System32\setx CATALINA_HOME "%tomcatpath%" -m
echo set temp var
setlocal
set "JAVA_HOME=%jdkpath%"
set "JRE_HOME=%jrepath%"
set "CATALINA_HOME=%tomcatpath%"
echo install tomcat service
call %cd%\apache-tomcat-7.0.35\bin\service.bat install
C:\Windows\System32\sc config Tomcat7 start= auto
C:\Windows\System32\net start Tomcat7
echo create desktop shortcut.
echo Do not close this window while creating a desktop shortcut.
set Program=%cd%\start.bat
set LnkName=appName.exe
set WorkDir=%cd%
set Desc=appName INSTRUCTIONS DOCUMENT
if not defined WorkDir call:GetWorkDir "%Program%"
(echo Set WshShell=CreateObject("WScript.Shell"^)
echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)
echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\%LnkName%.lnk"^)
echo oShellLink.TargetPath="%Program%"
echo oShellLink.WorkingDirectory="%WorkDir%"
echo oShellLink.WindowStyle=1
echo oShellLink.Description="%Desc%"
echo oShellLink.IconLocation = "%cd%\favicon.ico"
echo oShellLink.Save)>makelnk.vbs
echo desktop shortcut create successed!
makelnk.vbs
del /f /q makelnk.vbs
exit
start.bat 文件
echo off;
C:\Windows\System32\Net session >nul 2>&1 || C:\Windows\System32\WindowsPowerShell\v1.0\powershell start-process start000.bat -verb runas
start000.bat 文件
echo off;
C:\Windows\System32\sc start Tomcat7
start http://127.0.0.1:8080/appName/
unins.bat 文件
echo off;
C:\Windows\System32\net stop Tomcat7
C:\Windows\System32\sc delete Tomcat7
reg delete HKEY_CURRENT_USER\SOFTWARE\appName\config /f
unins000.exe
unins000.bat 文件
echo off;
C:\Windows\System32\net stop Tomcat7
C:\Windows\System32\sc delete Tomcat7
reg delete HKEY_CURRENT_USER\SOFTWARE\appName\config /f
uninstall.bat 文件
echo off;
C:\Windows\System32\Net session >nul 2>&1 || C:\Windows\System32\WindowsPowerShell\v1.0\powershell start-process unins000.bat -verb runas
timeout /t 3 /nobreak >nul
unins000.exe