gpt4 book ai didi

powershell - Win-PS2EXE-尊重生成的可执行文件的位置

转载 作者:行者123 更新时间:2023-12-03 00:41:49 28 4
gpt4 key购买 nike

对程序 Win-PS2EXE 进行以下设置:

这样一来,当单击exe文件时,控制台将显示出来。

Win-PS2EXE

这段代码:

$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文件时,我得到了。

enter image description here

有什么方法可以获取 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com