我正在从Chrome卸载程序中提取卸载字符串,以便使用此方法进行无人值守的静默卸载:
$UninstallStrings = Get-ItemProperty -Path "HKLM:\SOFTWARE\WoW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object{$_.DisplayName -like $ProgramName} |
Select-Object -ExpandProperty UninstallString -ea SilentlyContinue
给了我这个结果:
"C:\Program Files (x86)\Google\Chrome\Application\67.0.3396.79\Installer\setup.exe" --uninstall --system-level
现在继续卸载我想我需要修剪结果的参数,然后执行Start-Process
。任何人都可以提示删除参数的正确方法,并将其添加为-ArgumentsList
之后?
答案 0 :(得分:0)
我能想到的只是安装路径的一个非常简单的方法是根据用于启动参数的特殊字符进行拆分,在本例中为“ - ”,然后选择第一个条目。结果数组。
例如,如果你正处于这一点:
$UninstallStrings = Get-ItemProperty -Path "HKLM:\SOFTWARE\WoW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object{$_.DisplayName -like $ProgramName} |
Select-Object -ExpandProperty UninstallString -ea SilentlyContinue
然后您可以接受该变量,将其拆分为:
$ExpandedUninstallString = $UninstallStrings -split "--"
$UninstallCommand = $ExpandedUninstallString[0]
$Arguments = $ExpandedUninstallString[1..($ExpandedUninstallString.Length)]
哪个应该将$ UninstallCommand设置为仅指向卸载程序的字符串,并设置$ Arguments数组中的现有参数。
另请注意,除非您使用一些if语句定制它以检查installstring用作该特定应用程序的参数的字符,并将split分隔符定制到该特定参数列表,否则这不能扩展到其他应用程序。 / p>
答案 1 :(得分:0)
$ProgramName = "Google Chrome"
$EXEArgumente = "--uninstall --force-uninstall --system-level"
$UninstallStrings = Get-ItemProperty -Path "HKLM:\SOFTWARE\WoW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object{$_.DisplayName -like $ProgramName} | Select-Object -ExpandProperty UninstallString -ea SilentlyContinue
$ExpandedUninstallString = $UninstallStrings -split "--" -replace "`"",""
$UninstallCommand = $ExpandedUninstallString[0]
Start-Process $UninstallCommand -ArgumentList "$EXEArgumente"
这就是我现在的工作方式。谢谢你的帮助!