如何解决高级安装程序 powershell 内联脚本 APPDIR 为空
我正在使用高级安装程序。我想将一个目录从安装目录移动到另一个目录。问题是 APPDIR 变量为空。如何恢复安装目录? APPDIR 始终为空。 谢谢。
<#
.NOTES
"pwsh.exe" is run if required version is greater or equal to 6,otherwise
"powershell.exe" is invoked by default
#>
#Requires -version 3
Param($appDir)
$programFilesDir = [Environment]::GetEnvironmentvariable("ProgramFiles")
echo $appDir >> "D:\install.log"
echo "$appDir_Installation\Java" >> "D:\install.log"
echo "$programFilesDir" >> "D:\install.log"
copy-Item -Path "$appDir_Installation\Java" -Destination "$programFilesDir" -Recurse
解决方法
要对此进行故障排除,我建议您在代码中使用消息框来显示 $appDir 变量的值。只是为了确保它的值真的是空的。乍一看,APPDIR(安装文件夹)属性已正确传递给您的脚本,不应为空。
您可以将此代码添加到您的脚本中,并查看传递给 $appDir 变量的值是什么:
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.MessageBox]::Show($appDir)
,
您的 APPDIR 变量为空,因为您还需要在“参数值”选项中传递名称。
正如您在文档 Getting a property value into a script 中所读到的,您需要像这样配置:
-AppPath "[APPDIR]"
另外,你需要更新脚本的Param()块,它必须在第一行,如下:
Param($AppPath)
Check this script example which works,it is used to copy the files to another folder
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。