Add FirefoxService.ps1
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
class FirefoxService {
|
||||||
|
|
||||||
|
static [string] FindInstallDir() {
|
||||||
|
$candidates = @(
|
||||||
|
"C:\Program Files\Mozilla Firefox",
|
||||||
|
"C:\Program Files (x86)\Mozilla Firefox"
|
||||||
|
)
|
||||||
|
foreach ($c in $candidates) {
|
||||||
|
if (Test-Path (Join-Path $c "firefox.exe")) { return $c }
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$reg = Get-ItemProperty "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox" -ErrorAction Stop
|
||||||
|
if ($reg."Install Directory" -and (Test-Path $reg."Install Directory")) {
|
||||||
|
return $reg."Install Directory"
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
static [string] FindProfile() {
|
||||||
|
$profilesPath = Join-Path ([Environment]::GetFolderPath("ApplicationData")) "Mozilla\Firefox\Profiles"
|
||||||
|
if (-not (Test-Path $profilesPath)) { return $null }
|
||||||
|
$profiles = Get-ChildItem $profilesPath -Directory |
|
||||||
|
Where-Object { $_.Name -match '\.default|default-release' }
|
||||||
|
if ($profiles) { return $profiles[0].FullName }
|
||||||
|
$all = Get-ChildItem $profilesPath -Directory
|
||||||
|
if ($all) { return $all[0].FullName }
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
static [bool] IsRunning() {
|
||||||
|
return [bool](Get-Process -Name "firefox" -ErrorAction SilentlyContinue)
|
||||||
|
}
|
||||||
|
|
||||||
|
static [bool] IsAdmin() {
|
||||||
|
$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
return (New-Object System.Security.Principal.WindowsPrincipal($id)).IsInRole(
|
||||||
|
[System.Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||||
|
}
|
||||||
|
|
||||||
|
static [bool] IsIntuneManaged() {
|
||||||
|
$key = "HKLM:\SOFTWARE\Policies\Mozilla\Firefox"
|
||||||
|
if (Test-Path $key) {
|
||||||
|
return [bool](Get-ItemProperty $key -ErrorAction SilentlyContinue)
|
||||||
|
}
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
static [object[]] GetInstalledAddons([string]$profilePath) {
|
||||||
|
$json = Join-Path $profilePath "extensions.json"
|
||||||
|
if (-not (Test-Path $json)) { return @() }
|
||||||
|
return (Get-Content $json -Raw | ConvertFrom-Json).addons |
|
||||||
|
Where-Object { $_.type -eq "extension" }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user