我有一个PowerShell脚本,可以从添加/删除程序中删除LogMeIn(或按名称搜索的任何程序)。
这很好用但是我想删除LMI的所有实例,这意味着任何已经通过插件等本地安装的版本。
我想到这样做的唯一方法是删除相应的注册表项和应用程序数据 - 但是查询HKEY_USERS配置单元而不是HKCU配置单元是很麻烦的。
任何人都必须做类似的事情,他们在注册表中有一个他们想要突击的搜索词吗? 我已经尝试将HKEY_USERS映射到PS-Drive进行查询,但是无法正确使用术语。
function ForceUninstall {
Stop-Process -processname LMIGuardian*
Stop-Process -processname LogMeIn*
Stop-Process -processname LogMeInSystray*
Stop-Process -processname ramaint*
$null = New-PSDrive -PSProvider Registry -Name HKEY_USERS -Root HKEY_USERS
cd HKEY_USERS:/
$objects = get-childItem HKEY_USERS:\ -ErrorAction SilentlyContinue
foreach ($object in $objects){
$testpath = "$($object.name)\Software\LogMeIn"
$testpath = $testpath -replace [Regex]::Escape("HKEY_USERS\"),'HKEY_USERS:\'
$testpath2 = "$($object.name)\Software\LogMeIn Ignition"
$testpath2 = $testpath2 -replace [Regex]::Escape("HKEY_USERS\"),'HKEY_USERS:\'
If (test-path $testpath) {
$PathsToDelete += $testpath
}
If (test-path $testpath2) {
$PathsToDelete += $testpath2
}
}
foreach ($Path in $PathsToDelete){
write-host "removing $path"
(Get-ChildItem $Path).PsPath |Remove-Item -Recurse
"Deleted registry key"
}
$LocalPaths = @("HKEY_LOCAL_MACHINE:\System\Current Control Set\Services\LMIInfo",
"HKEY_LOCAL_MACHINE:\SOFTWARE\LogMeIn"
"HKEY_LOCAL_MACHINE:\System\Current Control Set\Services\LMIMaint",
"HKEY_LOCAL_MACHINE:\System\Current Control Set\Services\LMImirr",
"HKEY_LOCAL_MACHINE:\System\Current Control Set\Services\LMIRfsClientNP",
"HKEY_LOCAL_MACHINE:\System\Current Control Set\Services\LMIRfsDriver",
"HKEY_LOCAL_MACHINE:\System\Current Control Set\Services\LogMeIn")
$Location = New-PSDrive -PSProvider Registry -Name HKEY_LOCAL_MACHINE -Root HKEY_LOCAL_MACHINE
cd HKEY_LOCAL_MACHINE:/
foreach ($Path in $LocalPaths){
write-host "removing $path"
(Get-ChildItem $Path).PsPath |Remove-Item -Recurse
"Deleted registry key"
}
Remove-ItemProperty -Path "HKEY_LOCAL_MACHINE:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "LogMeIn GUI"
write-host "removed LogMeIn GUI file"
}