对程序 Win-PS2EXE 进行以下设置:
这样一来,当单击exe
文件时,控制台将显示出来。
这段代码:
$inf_file = "$PSScriptRoot\setup-files\install.inf"
write-host """$inf_file"""
timeout 10
我们说新可执行文件的路径是
W:\Apps\Install Scheme.exe
这意味着
$inf_file
在这里W:\Apps\setup-files\install.inf
当我单击转换后的exe文件时,我得到了。
有什么方法可以获取
W:\Apps\setup-files\install.inf
的正确路径,以便可执行文件在单击时可以识别其自身的位置。我以为
$PSScriptRoot
可以工作。我不知道如何解决此问题,因为exe文件最终将取决于知道其位置。
最佳答案
这是可以完成此任务的代码。
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript") {
$ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
} else {
$ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
if (!$ScriptPath){ $ScriptPath = "." }
}
write-host "$ScriptPath"
timeout 10
See the bottom of this page.
PS2EXE-GUI:使用GUI 将PowerShell脚本“转换”为EXE文件
https://gallery.technet.microsoft.com/PS2EXE-GUI-Convert-e7cb69d5
关于powershell - Win-PS2EXE-尊重生成的可执行文件的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60121313/