我用Inno Setup编写了一个脚本,它安装了一个带有一些Web应用程序的Jetty
用户可以选择安装目录,然后在Launcher.exe
中创建C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
文件的链接,以允许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:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\Launcher.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:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\Launcher.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
,则重启Windows后Jetty无法启动。
谢谢。
答案 0 :(得分:0)
As you found yourself the Launcher.exe
does not work at all when installed to "Program Files" unless it is run with Administrator privileges.
It most probably needs write permissions to its installation folder.
So there's nothing wrong with the shortcut. You just cannot install the Launcher.exe
to a directory where the user does not have a write access to.
Maybe there's some configuration option that can make the Launcher.exe
write the files, it needs, to a different directory than it is installed to.