Powershell 在软件安装过程中使用“启动过程”;msiexec.exe“-等等,如何修复错误并继续安装过程?
使用PowerShell命令安装“自托管集成运行时软件” 启动进程“msiexec.exe”“/i$path/quiet/passive”-等待,由于“DIAHostService”没有“LocalSystem”访问权限,出现错误。 我有将登录名更改为LocalSystem(“sc.exe config”ServiceName“obj=“LocalSystem”)的代码,但在安装过程中如何做到这一点,如何捕捉错误并进行所需更改并自动继续安装 代码:-Powershell 在软件安装过程中使用“启动过程”;msiexec.exe“-等等,如何修复错误并继续安装过程?,powershell,Powershell,使用PowerShell命令安装“自托管集成运行时软件” 启动进程“msiexec.exe”“/i$path/quiet/passive”-等待,由于“DIAHostService”没有“LocalSystem”访问权限,出现错误。 我有将登录名更改为LocalSystem(“sc.exe config”ServiceName“obj=“LocalSystem”)的代码,但在安装过程中如何做到这一点,如何捕捉错误并进行所需更改并自动继续安装 代码:- param([string]$path, [
param([string]$path, [string]$authKey)
function Install-Gateway([string] $gwPath)
{
# uninstall any existing gateway
UnInstall-Gateway
Write-Host "Start Gateway installation"
Start-Process "msiexec.exe" "/i $path /quiet /passive" -Wait
Start-Sleep -Seconds 30
Write-Host "Succeed to install gateway"
}
因为我无法复制您正在做的事情,所以以这种通用方法为例
param([string]$path, [string]$authKey)
function Install-Gateway([string] $gwPath)
{
Write-Warning -Message 'Starting Gateway uninstallation'
UnInstall-Gateway
Try
{
'Starting Gateway installation'
Start-Process -FilePath 'msiexec.exe' -ArgumentList "/i $path /quiet /passive" -Wait -ErrorAction Stop
Start-Sleep -Seconds 30
Write-Verbose -Message 'Gateway installation successful.' -Verbose
}
Catch
{
Write-Warning -Message 'AN error occurred'
$PSItem.Exception.Message
}
}
如果需要与其他用户一起运行,则需要将运行方式添加为启动进程错误逻辑的一部分。然而,使用RunAs意味着启动一个新的Powershell实例。它不会在同一进程中运行
参考资料
•
将其放在脚本或脚本中的函数中,然后使用Try/Catch。这已在函数中。但在执行过程中,控件不会从“启动进程…”命令移动到下一个命令以进行所需的更改。没有暂停选项。您需要显示代码。---这里有完整的代码-或者我如何使用“LocalSystem”帐户运行“启动进程”msiexec.exe“/I$path/quiet/passive”-Wait”。默认情况下,它在NT帐户上运行。如何使用PS命令实现这一点?