[英]Syntax error with Uninstaller using Powershell
I'm trying to get my universal uninstaller working.我正在尝试让我的通用卸载程序正常工作。 Here is my code:
这是我的代码:
CLS
$Software = "Zoom"
$Filter = "*" + $Software + "*"
$Program = $ProgUninstall = $FileUninstaller = $FileArg = $NULL
try
{
if (Test-Path -Path "HKLM:\SOFTWARE\WOW6432Node")
{
$programs = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction Stop
}
$programs += Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction Stop
$programs += Get-ItemProperty -Path "Registry::\HKEY_USERS\*\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction SilentlyContinue
}
catch
{
Write-Error $_
break
}
foreach($Program in $Programs)
{
$ProgDisplayName = $Program.DisplayName
$ProgUninstall = $Program.UninstallString
if($ProgDisplayName -like $Filter)
{
#$Program
$aux = $ProgUninstall -split @('\.exe'),2,[System.StringSplitOptions]::None
$Uninstaller = (cmd /c echo $($aux[0].TrimStart('"').TrimStart("'") + '.exe')).Trim('"')
$UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)
if($aux -notlike "param 0 = *")
{
# $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)
}
$Uninstaller
$UninsParams
# . $Uninstaller $UninsParams | Where-Object { $_ -notlike "param 0 = *" }
}
}
In my example I'm trying to get an output for Zoom.在我的示例中,我试图获得 Zoom 的输出。 I have the Zoom client installed and the Zoom Outlook plugin installed.
我安装了 Zoom 客户端并安装了 Zoom Outlook 插件。
Here is the output of the program:这是程序的输出:
DisplayName : Zoom Outlook Plugin
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{0B76DE11-5937-4491-A66A-617E42170AFF}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName : {0B76DE11-5937-4491-A66A-617E42170AFF}
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
You cannot call a method on a null-valued expression.
At line:34 char:9
+ $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
AuthorizedCDFPrefix :
Comments : Zoom
Contact : Zoom Video Communications, Inc.
DisplayVersion : 5.4.58891
HelpLink : https://support.zoom.us/home
HelpTelephone :
InstallDate : 20201119
InstallLocation :
InstallSource : C:\temp\Zoom\
ModifyPath : MsiExec.exe /X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
NoModify : 1
Publisher : Zoom
Readme :
Size :
EstimatedSize : 122109
UninstallString : MsiExec.exe /X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
URLInfoAbout : https://zoom.us
URLUpdateInfo :
VersionMajor : 5
VersionMinor : 4
WindowsInstaller : 1
Version : 84207115
Language : 1033
DisplayName : Zoom
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{3109C49B-F5E4-4FEC-8F6F-EC5E4626B36
1}
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName : {3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
Part of the problem from what I can tell is the Zoom Outlook plugin doesn't have any uninstall strings associated with it.我所知道的部分问题是 Zoom Outlook 插件没有任何与之关联的卸载字符串。 I'm assuming it's just part of the Zoom Client (even though it's a seperate installer).
我假设它只是 Zoom Client 的一部分(即使它是一个单独的安装程序)。 What I'm trying to do is get this code to work without throwing any errors or displaying false positives.
我想要做的是让这段代码正常工作,而不会抛出任何错误或显示误报。
Here is the output of my 2 parms "$Uninstaller" and "$UninsParams"这是我的 2 个参数“$Uninstaller”和“$UninsParams”的输出
You cannot call a method on a null-valued expression.
At line:34 char:9
+ $UninsParams = $aux[1].TrimStart('"').TrimStart("'").Trim().s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
.exe
/X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
MsiExec.exe
/X{3109C49B-F5E4-4FEC-8F6F-EC5E4626B361}
Thanks in advance!提前致谢!
The problem here is that since the Zoom Client Plugin doesn't have an uninstall script, your -split
operation evaluates to a single empty string , and $aux[1]
therefore evaluates to $null
, hence the error message.这里的问题是,由于 Zoom 客户端插件没有卸载脚本,您的
-split
操作评估为单个空 string ,因此$aux[1]
评估为$null
,因此出现错误消息。
You could filter out entries without a valid UninstallString
:您可以过滤掉没有有效
UninstallString
条目:
foreach($Program in $Programs |Where-Object UninstallString -match '\.exe')
{
# ... now you don't need to worry about this not resulting in two strings
$aux = $ProgUninstall -split @('\.exe'),2,[System.StringSplitOptions]::None
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.