通过 powershell 以管理员身份启动 msiexec
Launch msiexec as an admin through powershell
我在处理一段与执行 MSI 应用程序相关的代码时遇到了问题。
我需要传递存储在变量中的凭据,然后通过 "runas" 将这些凭据传递给 MSI 包,以便它与我传递给应用程序的升级凭据一起安装。
这是我遇到问题的代码部分。
if($filter -like "*.msi")
{
Start-Process -FilePath "msiexec $FullFilePath" -Credential $adminCreds -ArgumentList "-noprofile -command &{Start-Process /i $FullFilePath /passive /norestart -verb runas}" -Wait -WorkingDirectory $path
exit
}
我的变量如下:
$filter = Get-ChildItem $path -Filter $($installer[$i]) -name
$FullFilePath = $path + "\" + $filter
$path = Split-Path $script:MyInvocation.MyCommand.Path
提前致谢!
为了解决我的问题,我创建了一个代码块,用于导出临时批处理脚本,以在执行脚本的文件夹中查找任何 msi 应用程序。一旦脚本是 运行,并且安装了应用程序,脚本就会自行删除。我通过批处理脚本而不是直接通过 MSI 应用程序传递凭据,但这可以满足我的需要。这是对我的脚本所做的更改。
$msiBatch = @"
@echo off
pushd "%~dp0"
::Get the MSI file name to install
for /f "tokens=1* delims=\" %%A in ( 'forfiles /s /m *.msi /c "cmd /c echo @relpath"' ) do for %%F in (^"%%B) do (set myapp=%%~F)
::Launch our installer
start /w "" msiexec /i "%~dp0%myapp%" /passive /norestart
::Self Delete
DEL "%~f0"
"@
事情是这样的运行:
if($filter -like "*.msi")
{
$installPath = $path + "\msiInstaller.bat"
$msiBatch | Out-File -Encoding Ascii -append $installPath
$FullFilePath = $installPath
}
Start-Process -FilePath powershell.exe -Credential $adminCreds -NoNewWindow -ArgumentList "-noprofile -command &{Start-Process $FullFilePath -verb runas}" -Wait -WorkingDirectory $path
break
我在处理一段与执行 MSI 应用程序相关的代码时遇到了问题。 我需要传递存储在变量中的凭据,然后通过 "runas" 将这些凭据传递给 MSI 包,以便它与我传递给应用程序的升级凭据一起安装。
这是我遇到问题的代码部分。
if($filter -like "*.msi")
{
Start-Process -FilePath "msiexec $FullFilePath" -Credential $adminCreds -ArgumentList "-noprofile -command &{Start-Process /i $FullFilePath /passive /norestart -verb runas}" -Wait -WorkingDirectory $path
exit
}
我的变量如下:
$filter = Get-ChildItem $path -Filter $($installer[$i]) -name
$FullFilePath = $path + "\" + $filter
$path = Split-Path $script:MyInvocation.MyCommand.Path
提前致谢!
为了解决我的问题,我创建了一个代码块,用于导出临时批处理脚本,以在执行脚本的文件夹中查找任何 msi 应用程序。一旦脚本是 运行,并且安装了应用程序,脚本就会自行删除。我通过批处理脚本而不是直接通过 MSI 应用程序传递凭据,但这可以满足我的需要。这是对我的脚本所做的更改。
$msiBatch = @"
@echo off
pushd "%~dp0"
::Get the MSI file name to install
for /f "tokens=1* delims=\" %%A in ( 'forfiles /s /m *.msi /c "cmd /c echo @relpath"' ) do for %%F in (^"%%B) do (set myapp=%%~F)
::Launch our installer
start /w "" msiexec /i "%~dp0%myapp%" /passive /norestart
::Self Delete
DEL "%~f0"
"@
事情是这样的运行:
if($filter -like "*.msi")
{
$installPath = $path + "\msiInstaller.bat"
$msiBatch | Out-File -Encoding Ascii -append $installPath
$FullFilePath = $installPath
}
Start-Process -FilePath powershell.exe -Credential $adminCreds -NoNewWindow -ArgumentList "-noprofile -command &{Start-Process $FullFilePath -verb runas}" -Wait -WorkingDirectory $path
break