# Script to install and uninstall Mozilla Firefox on Windows devices.

Mozilla Firefox offers advanced privacy and security features, which makes it ideal for enterprise use. However, manual installation/uninstallation of the app can become a hassle when needed to be done on a large number of devices. Using Hexnode’s [custom script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) feature, administrators can install or uninstall Firefox remotely across all deployed Windows devices.

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

PowerShell script
-----------------

### Install Firefox

To install Firefox on a Window device, use the following script:

Script to install Firefox on a Windows device

$workdir = "c:\\installer\\" If (Test-Path -Path $workdir -PathType Container) { Write-Host "$workdir already exists" -ForegroundColor Red} ELSE { New-Item -Path $workdir -ItemType directory } $source = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US" $destination = "$workdir\\firefox.exe" if (Get-Command 'Invoke-Webrequest') { Invoke-WebRequest $source -OutFile $destination } else { $WebClient = New-Object System.Net.WebClient $webclient.DownloadFile($source, $destination) } Start-Process -FilePath "$workdir\\firefox.exe" -ArgumentList "/S" Start-Sleep -s 35 rm -Force $workdir/firefox\* Write-Host "Successfully installed Firefox application."

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

  $workdir = "c:\\installer\\" 

If (Test-Path -Path $workdir -PathType Container) 

{ Write-Host "$workdir already exists" -ForegroundColor Red} 

ELSE 

{ New-Item -Path $workdir -ItemType directory }

$source = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US" 

$destination = "$workdir\\firefox.exe"

if (Get-Command 'Invoke-Webrequest')

{

Invoke-WebRequest $source -OutFile $destination

}

else

{

$WebClient = New-Object System.Net.WebClient

$webclient.DownloadFile($source, $destination)

}

Start-Process -FilePath "$workdir\\firefox.exe" -ArgumentList "/S"

Start-Sleep -s 35

rm -Force $workdir/firefox\*

Write-Host "Successfully installed Firefox application."

   

 

  

This will download the installer file in `c:\installer\` and subsequently use it to install the application on your device.

###  Uninstall Firefox

The following script will help you uninstall Firefox:

Script to uninstall Firefox on a Windows device

try { $appExists = $true $filePath = "C:\\Program Files\\Mozilla Firefox\\uninstall\\helper.exe" if(-not(Test-Path $filePath)) { $filePath = "C:\\Program Files (x86)\\Mozilla Firefox\\uninstall\\helper.exe" if(-not(Test-Path $filePath)) { $appExists = $false } } if($appExists) { Start-Process -FilePath $filePath -ArgumentList "/s" -Wait Write-Host "Successfully uninstalled Firefox application." } else { Write-Host "Firefox is not installed on this device.”} } catch { Write-Host $\_.Execption.Message }

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

  try

{

$appExists = $true

$filePath = "C:\\Program Files\\Mozilla Firefox\\uninstall\\helper.exe"

if(-not(Test-Path $filePath))

{

$filePath = "C:\\Program Files (x86)\\Mozilla Firefox\\uninstall\\helper.exe"

if(-not(Test-Path $filePath))

{

$appExists = $false

}

}

if($appExists)

{

Start-Process -FilePath $filePath -ArgumentList "/s" -Wait

Write-Host "Successfully uninstalled Firefox application."

}

else

{

Write-Host "Firefox is not installed on this device.”}

}

catch

{

Write-Host $\_.Execption.Message

}

   

 

  

This will check the device for the helper application required to uninstall the application and run it to uninstall Mozilla Firefox. In case the app is not installed on the device, it will relay that **Firefox is not installed on this device** as output.

 Notes:- If the helper file has been installed at a different location on the device than **C:\\Program Files\\Mozilla Firefox**, provide the file path for the helper file at `$filepath` to uninstall the application.
- Mozilla Firefox app should have been installed using either the above script or using an MSI file as an [Enterprise app](https://www.hexnode.com/mobile-device-management/help/distribute-enterprise-apps-msi-to-windows-10-devices/) for the script to successfully uninstall the app.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.