powershell - 来自注册表提取的 PowerShell 剩余字符
问题描述
从注册表中提取此安装字符串时,有一个不可见的前导字符。
我无法运行卸载字符串或删除此字符。拆分、替换、连接等的各种迭代对字符串起作用,但对改变错误行为没有任何作用。我在 PowerShell 或 Windows 控制台中尝试过。
Write-Output $uninst
显示正确的字符串:
MsiExec.exe /x {1F4D7BAB-E816-43DF-B4B1-5A41A2DA13E8} /qn
在 PowerShell 中执行该字符串时,会msiexec
弹出帮助气泡。在 Windows CMD shell 中执行该字符串时,白色方形字符位于行首。
# pull ESET uninstall string
$esetVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object { $_.DisplayName -match "ESET Endpoint Antivirus" } |
Select-Object -Property DisplayName, UninstallString
foreach ($ver in $esetVer) {
if ($ver.UninstallString) {
$uninst = $ver.UninstallString
$uninst = $uninst.Replace('/I{',' /x {').Replace('}','} /qn')
Invoke-Expression $uninst
Write-Output $uninst
}
}
删除第一个字符只会删除 M。
解决方案
在我的问题中,我关注 msiexec.exe 命令行之前的一些错误字符。这显然不是问题所在。问题在于应用 ID ( {1F4D7BAB-E816-43DF-B4B1-5A41A2DA13E8} ) 周围的括号。他们需要一个反引号。因此,只需在我的替换行中的大括号之前包含反引号即可修复代码。
旧:$uninst = $uninst.Replace('/I{',' /x {').Replace('}','} /qn')
新:$uninst = $uninst.Replace('/I{',' /x {').Replace('}','
} /qn')
此修改适用于 2 台 Windows 7 Pro 计算机。
推荐阅读
- python - Python 3,Pandas csv 行,在某些字段中嵌套了键/值。如何将其压平成一排宽
- delphi - 如何将结果编码为组合框中的选择?
- css - 在反应 mui 组件上使用 css codepen
- powershell - Powershell附加了文件夹中的所有文件
- javascript - 导入 fuse.js 库时出现打字稿错误
- javascript - 使用 vue-i18n 转换 Vue 组件 prop 的默认值
- c# - Azure 静态网站是否支持使用 https 的主机名映射
- node.js - 了解 Azure Function 中的 Mongoose 连接
- javascript - 如何在按钮的不同点击中调用不同的 JS 函数?
- c - c语言中可能的函数重载?