我用Inno Setup编写了一个脚本,该脚本使用一些Web应用程序安装了一个Jetty。
用户可以选择安装目录,之后,在C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUp
中创建指向Launcher.exe
文件的链接,以允许 Jetty 在 Windows 启动时自动启动。
这里的代码:
[Setup]
AppName=Wr Addon
AppVersion=1.0
AppPublisher=Hitachi Systems CBT S.p.A.
;the default directory where program is installed
UninstallDisplayName=Wr Addon
;give to the use the chance to choose the install directory
DisableDirPage=no
DefaultDirName=WrAddon
;the directory where is placed the uninstaller, the path the destination dir choosed by the user with the uninstall subdirectory
UninstallFilesDir={app}uninstall
[Setup]
;Request to restart the system after to install the program.
AlwaysRestart = yes
[Files]
Source: "jetty-distribution-9.3.6.v20151106*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
;create a link to the Launcher.exe in the StartUp directory of Windows
[Icons]
Name: C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUpLauncher.exe; Filename: "{app}Launcher.exe"
;run the stop.bat file during the uninstall phase to close the Java tasks and allow to delete the program folder
[UninstallRun]
Filename: "{app}stop.bat"; Parameters: "/x"; Flags: waituntilterminated
;delete all files and directories (also new file created during the jetty execution)
[UninstallDelete]
Type: files; Name: "{app}*";
Type: filesandordirs; Name: "{app}"
[Code]
const LINKPATH = 'C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUpLauncher.lnk';
//procedure DeinitializeSetup();
//var
// ShortcutPath: string;
//begin
// ShortcutPath := CreateShellLink(LINKPATH, 'Shortcut to Launcher.exe', ExpandConstant('{app}Launcher.exe'), '', LINKPATH, '', 0, SW_SHOWNORMAL);
// MsgBox('shortcut created in '+ShortcutPath, mbInformation, MB_OK);
//end;
如果安装目录未C:Program Files (x86)
或未C:Program Files
,安装程序将正确创建链接请注意,我尝试通过以下方式创建链接:
- 与
[Icons]
- 与
CreateShellLink
(评论)
行为是相同的。
如果我将安装放在其他目录(例如Desktop
或C:
中),它可以正常工作。
我怀疑管理员权限是否存在一些问题,因为如果安装目录不C:Program Files (x86)
或C:Program Files
,当我重新启动Windows时,Jetty会正常启动。
如果目录安装是 C:Program Files (x86)
或 C:Program Files
,则 Jetty 在重新启动 Windows 后不会启动。
谢谢。
正如您发现自己的那样,除非以管理员权限运行,否则Launcher.exe
在安装到"程序文件"时根本不起作用。
它很可能需要对其安装文件夹的写入权限。
所以捷径没有错。您只是无法将Launcher.exe
安装到用户没有写入访问权限的目录中。
也许有一些配置选项可以使Launcher.exe
将所需的文件写入与安装到不同的目录。