问题描述
我正在使用高级安装程序。我想将一个目录从安装目录移动到另一个目录。问题是 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