PS 脚本从多个位置卸载 Firefox

发布于 2025-01-16 04:28:59 字数 3024 浏览 4 评论 0原文

我正在创建一个脚本来从多个位置卸载 Firefox。我有一个我创建的脚本,它在一定程度上有效。我已根据下面的答案以及其他一些更改对原始脚本进行了更改

$LocalUsers = (Get-ChildItem -Path "C:\Users").name

# Uninstalling from Program Files
if (Test-Path "${env:ProgramFiles(x86)}\Mozilla Firefox\uninstall\helper.exe"){
    Start-Process -FilePath "${env:ProgramFiles(x86)}\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
}
if (Test-Path "${env:ProgramFiles}\Mozilla Firefox\uninstall\helper.exe"){
    Start-Process -FilePath "${env:ProgramFiles}\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
}

# Uninstalling for each user
ForEach ($LocalUser in $LocalUsers){
    $Userpath = "C:\Users\" + $LocalUser
    if (Test-Path "$Userpath\AppData\Local\Mozilla Firefox\uninstall\helper.exe"){
        Start-Process -FilePath "$Userpath\AppData\Local\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
    }

    Start-Sleep 20

    # Remove shortcuts from appdata
    Remove-Item -Path "$userpath\AppData\Local\Mozilla" -Force -Recurse -Verbose #-ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\AppData\LocalLow\Mozilla" -Force -Recurse -Verbose #-ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Firefox.lnk" -Force -Verbose #-ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\desktop\firefox.lnk" -Force -Verbose #-ErrorAction SilentlyContinue
}

# Remove related registry keys
$pathToRemove = @(
    'HKLM:\Software\Mozilla'
    'HKLM:\SOFTWARE\mozilla.org'
    'HKLM:\SOFTWARE\MozillaPlugins'
    'HKLM:\SOFTWARE\WOW6432Node\Mozilla'
    'HKLM:\SOFTWARE\WOW6432Node\mozilla.org'
    'HKLM:\SOFTWARE\WOW6432Node\MozillaPlugins'
    'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Firefox.lnk'
)

foreach($path in $pathToRemove) {
    if(Test-Path $path) {
        try {
            Remove-Item $path -Recurse -Force -Verbose #-ErrorAction SilentlyContinue
        }
        catch {
            Write-Warning $_.Exception.Message
        }
    }
}

该脚本已在某些计算机上运行,​​其中它卸载了应用程序,但是,对于其他计算机,它的痕迹被留在 Windows 程序文件中。它显示为死链接。我知道这是一个死链接,因为它缺少 Firefox 徽标。 指向 %localappdata%\Mozilla Firefox\uninstall\helper.exe

奇怪的是它根据错误DealLink1DeadLink2

错误1错误 2

安装后应用程序应该是什么样子(忽略版本,只是网上的屏幕截图):

ifinstalled

I am working on creating a script to uninstall Firefox from multiple locations. I have a script that I've created and it works to an extent. I have made changes to my original script based on the answer below plus some other changes

$LocalUsers = (Get-ChildItem -Path "C:\Users").name

# Uninstalling from Program Files
if (Test-Path "${env:ProgramFiles(x86)}\Mozilla Firefox\uninstall\helper.exe"){
    Start-Process -FilePath "${env:ProgramFiles(x86)}\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
}
if (Test-Path "${env:ProgramFiles}\Mozilla Firefox\uninstall\helper.exe"){
    Start-Process -FilePath "${env:ProgramFiles}\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
}

# Uninstalling for each user
ForEach ($LocalUser in $LocalUsers){
    $Userpath = "C:\Users\" + $LocalUser
    if (Test-Path "$Userpath\AppData\Local\Mozilla Firefox\uninstall\helper.exe"){
        Start-Process -FilePath "$Userpath\AppData\Local\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
    }

    Start-Sleep 20

    # Remove shortcuts from appdata
    Remove-Item -Path "$userpath\AppData\Local\Mozilla" -Force -Recurse -Verbose #-ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\AppData\LocalLow\Mozilla" -Force -Recurse -Verbose #-ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Firefox.lnk" -Force -Verbose #-ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\desktop\firefox.lnk" -Force -Verbose #-ErrorAction SilentlyContinue
}

# Remove related registry keys
$pathToRemove = @(
    'HKLM:\Software\Mozilla'
    'HKLM:\SOFTWARE\mozilla.org'
    'HKLM:\SOFTWARE\MozillaPlugins'
    'HKLM:\SOFTWARE\WOW6432Node\Mozilla'
    'HKLM:\SOFTWARE\WOW6432Node\mozilla.org'
    'HKLM:\SOFTWARE\WOW6432Node\MozillaPlugins'
    'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Firefox.lnk'
)

foreach($path in $pathToRemove) {
    if(Test-Path $path) {
        try {
            Remove-Item $path -Recurse -Force -Verbose #-ErrorAction SilentlyContinue
        }
        catch {
            Write-Warning $_.Exception.Message
        }
    }
}

The script has worked on some machines where it uninstalls the application, however, for others trace of it is being left behind in Windows Program Files. It is appearing as a dead link. I know it is a dead link because it is missing the Firefox logo. The strange thing is its points to %localappdata%\Mozilla Firefox\uninstall\helper.exe per the error

DealLink1
DeadLink2

Error 1
Error 2

What the app should look like if installed (ignoring the version just a screenshot from online):

ifinstalled

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2025-01-23 04:28:59

我假设问题是您的链接 if \ elseif \ else 条件,可能发生的情况是,如果第一个条件是 $true 您只删除第一个注册表项,然后退出链接条件(这是设计使然):

# only results in 'hello if' and then exits the chained conditions

if($true) {
    'hello if'
}
elseif($true) {
    'hello elseif'
}

在这种情况下您可以做的是将所有路径存储在数组中,然后循环它们,测试该路径是否存在,如果存在,则将其删除:

$pathToRemove = @(
    'HKLM:\Software\Mozilla'
    'HKLM:\SOFTWARE\mozilla.org'
    'HKLM:\SOFTWARE\MozillaPlugins'
    'HKLM:\SOFTWARE\WOW6432Node\Mozilla'
    'HKLM:\SOFTWARE\WOW6432Node\mozilla.org'
    'HKLM:\SOFTWARE\WOW6432Node\MozillaPlugins'
    'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Firefox.lnk'
)

foreach($path in $pathToRemove) {
    if(Test-Path $path) {
        try {
            Write-Verbose "Attempting to remove: $path" -Verbose
            Remove-Item $path -Recurse -Force
            Write-Verbose "Successfully removed: $path" -Verbose
        }
        catch {
            Write-Warning $_.Exception.Message
        }
    }
}

I'm assuming the problem is your chained if \ elseif \ else conditions, what could be happening is that if the first condition was $true you're only removing the first registry key and then exiting the chained conditions (this is by design):

# only results in 'hello if' and then exits the chained conditions

if($true) {
    'hello if'
}
elseif($true) {
    'hello elseif'
}

What you can do in this case is store all the paths in an array and then loop over them, testing if the path exists and, if it does, remove it:

$pathToRemove = @(
    'HKLM:\Software\Mozilla'
    'HKLM:\SOFTWARE\mozilla.org'
    'HKLM:\SOFTWARE\MozillaPlugins'
    'HKLM:\SOFTWARE\WOW6432Node\Mozilla'
    'HKLM:\SOFTWARE\WOW6432Node\mozilla.org'
    'HKLM:\SOFTWARE\WOW6432Node\MozillaPlugins'
    'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Firefox.lnk'
)

foreach($path in $pathToRemove) {
    if(Test-Path $path) {
        try {
            Write-Verbose "Attempting to remove: $path" -Verbose
            Remove-Item $path -Recurse -Force
            Write-Verbose "Successfully removed: $path" -Verbose
        }
        catch {
            Write-Warning $_.Exception.Message
        }
    }
}
夜未央樱花落 2025-01-23 04:28:59

我在 winget 安装失败时遇到了同样的问题,并发现了一个遗留的注册表项。当它从列表中删除并允许重新安装时。

添加到您的注册表项删除数组:
'HKCU:\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Mozilla Firefox*'

I was having this same issue from a failed winget install, and found a registry key that was left behind. When it was removed from the list and allowed for reinstallation.

add to your registry key removal array:
'HKCU:\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Mozilla Firefox*'

爱已欠费 2025-01-23 04:28:59

我认为为了将每个用户配置文件“删除”它..
您需要在 ForEach ($LocalUser in $LocalUsers) { 部分将用户的注册表配置单元加载到“User”,然后从加载的配置单元中搜索并删除 reg 密钥。然后卸载蜂巢...

I think in order to have it "removed" for each user profile..
You would need to during the ForEach ($LocalUser in $LocalUsers) { section load the registry hive of the user to "User" then search and remove the reg key from the loaded hive.. Then unload the hive...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文