【发布时间】:2017-05-16 19:00:16
【问题描述】:
以下是 NSIS 安装程序的摘录。
我的问题是当我执行时:
CreateShortCut "$DESKTOP\PRESS_Survey_PS.lnk" $shortcutPath "" $INSTDIR\images\appIcons\Survey.ico
它使用变量 $shortcutPath 在快捷方式的目标字段中生成:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command &.\PRESS_Survey.ps1"
$shortcutPath 变量是使用以下 strcpy 构建的:
StrCpy $powerShellPath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "
StrCpy $shortcutPath $powerShellPath$\"&.\PRESS_Survey.ps1$\"
当我将 $shortcutPath 变量写入我的 ps1 文件时:
FileWrite $0 $powershellComment$shortcutPath$NewLine
它产生这个:
#C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "&.\PRESS_Survey.ps1"
当我尝试使用以下命令执行快捷方式时:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command &.\PRESS_Survey.ps1"
它失败了,询问 PRESS_Survey.ps1 的位置。
当我在目标字段中将 CreateShortCut 版本替换为 FileWrite 版本时:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "&.\PRESS_Survey.ps1"
它运行。
为什么在两个实例中 $shortcutPath 的值不一样? 这是我做错了什么还是Windows快捷方式问题? 无论哪种情况,有没有办法解决这个问题?
提前致谢。
【问题讨论】:
标签: powershell nsis