Skip to content

Commit caf7cea

Browse files
committed
remove-browserhijack scheduler
1 parent 02e94cd commit caf7cea

File tree

1 file changed

+95
-90
lines changed

1 file changed

+95
-90
lines changed

Modules/Scripts/Remove-BrowserHijack.ps1

+95-90
Original file line numberDiff line numberDiff line change
@@ -15,107 +15,112 @@ Removes the schedule task.
1515
#>
1616
[CmdletBinding(DefaultParameterSetName = 'Fix')]
1717
param(
18-
[Parameter(ParameterSetName = 'Install')]
19-
[switch] $Install = $false,
20-
[Parameter(ParameterSetName = 'Uninstall')]
21-
[switch] $Uninstall = $false
18+
[Parameter(ParameterSetName = 'Install')]
19+
[switch] $Install = $false,
20+
[Parameter(ParameterSetName = 'Uninstall')]
21+
[switch] $Uninstall = $false
2222
)
2323

2424
Begin
2525
{
26-
$taskName = 'Remove-BrowserHijack'
26+
$taskName = 'Remove-BrowserHijack'
2727

28-
function RegisterTask
29-
{
30-
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
28+
function RegisterTask
29+
{
30+
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
3131

32-
$pwsh = [System.Diagnostics.Process]::GetCurrentProcess().Path
33-
$command = "& '${PSCommandPath}'"
34-
$command = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($command))
32+
$pwsh = [System.Diagnostics.Process]::GetCurrentProcess().Path
3533

36-
$action = New-ScheduledTaskAction -Execute $pwsh `
37-
-Argument "-NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -EncodedCommand ${command}"
34+
$log = Join-Path $env:USERPROFILE "task-logs\$taskName.log"
35+
$command = "Start-Transcript $log; & '${PSCommandPath}'"
36+
#$command = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($command))
3837

39-
$dailyTrigger = New-ScheduledTaskTrigger -Daily -At '7:00'
40-
$logonTrigger = New-ScheduledTaskTrigger -AtLogOn -User $user
38+
$action = New-ScheduledTaskAction -Execute $pwsh `
39+
-Argument "-NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command ""${command}"""
40+
#-Argument "-NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -EncodedCommand ${command}"
4141

42-
Register-ScheduledTask $taskName -Action $action -Trigger $dailyTrigger, $logonTrigger -User $user -RunLevel Highest
43-
}
42+
$dailyTrigger = New-ScheduledTaskTrigger -Daily -At 6am
43+
$logonTrigger = New-ScheduledTaskTrigger -AtLogOn -User $user
44+
45+
Register-ScheduledTask $taskName -Action $action -Trigger $dailyTrigger, $logonTrigger -User $user -RunLevel Highest
46+
}
4447

45-
function UnregisterTask
46-
{
47-
Unregister-ScheduledTask $taskName
48-
}
49-
50-
51-
function RemoveHijack
52-
{
53-
param($0, $p)
54-
if (Test-Path $0)
55-
{
56-
$p | foreach {
57-
if ((Get-ItemProperty $0).$_ -ne $null) {
58-
Write-Host "removing $0 " -NoNewline -ForegroundColor DarkGray
59-
Write-Host $_
60-
Remove-ItemProperty $0 $_
61-
}
62-
}
63-
}
64-
}
65-
66-
function RemoveHijackKey
67-
{
68-
param($0)
69-
if (Test-Path $0) {
70-
Write-Host "removing $0"
71-
Remove-Item -Force -Recurse $0
72-
}
73-
}
48+
function UnregisterTask
49+
{
50+
Unregister-ScheduledTask $taskName -Confirm:$false
51+
}
52+
53+
54+
function RemoveHijack
55+
{
56+
param($0, $p)
57+
if (Test-Path $0)
58+
{
59+
$p | foreach {
60+
if ((Get-ItemProperty $0).$_ -ne $null)
61+
{
62+
Write-Host "removing $0 " -NoNewline -ForegroundColor DarkGray
63+
Write-Host $_
64+
Remove-ItemProperty $0 $_
65+
}
66+
}
67+
}
68+
}
69+
70+
function RemoveHijackKey
71+
{
72+
param($0)
73+
if (Test-Path $0)
74+
{
75+
Write-Host "removing $0"
76+
Remove-Item -Force -Recurse $0
77+
}
78+
}
7479
}
7580
Process
7681
{
77-
if ($PSCmdlet.ParameterSetName -eq 'Install')
78-
{
79-
RegisterTask
80-
return
81-
}
82-
83-
if ($PSCmdlet.ParameterSetName -eq 'Uninstall')
84-
{
85-
UnregisterTask
86-
return
87-
}
88-
89-
# fix it now!
90-
91-
# Chrome
92-
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
93-
RemoveHijack 'HKLM:\SOFTWARE\Policies\Google\Chrome' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
94-
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome\Recommended' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
95-
RemoveHijack 'HKLM:\SOFTWARE\Policies\Google\Chrome\Recommended' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
96-
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs' @('HomepageLocation')
97-
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome\Recommended\RestoreOnStartupURLs' @('HomepageLocation')
98-
99-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Chrome~Policy~googlechrome~Startup'
100-
RemoveHijackKey 'HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs'
101-
RemoveHijackKey 'HKLM:\SOFTWARE\WOW6432Node\Policies\Google\Chrome\RestoreOnStartupURLs'
102-
RemoveHijackKey 'HKLM:\SOFTWARE\WOW6432Node\Policies\Google\Chrome\Recommended\RestoreOnStartupURLs'
103-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\Chrome~Policy~googlechrome_recommended~Startup_recommended'
104-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\Chrome~Policy~googlechrome~Startup'
105-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\Providers\89FA9032-04AF-4BA8-BD43-936A846F7EFE\default\Device\Chrome~Policy~googlechrome~Startup'
106-
107-
# Edge
108-
RemoveHijack 'HKCU:\SOFTWARE\Policies\Microsoft\Edge\Recommended' @('HomepageLocation', 'RestoreOnStartup', 'ShowHomeButton', 'InternetExplorerIntegrationSiteList')
109-
RemoveHijack 'HKCU:\SOFTWARE\Policies\Microsoft\Edge\Internet Settings' @('ProvisionedHomePages')
110-
RemoveHijack 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' @('HomepageLocation', 'RestoreOnStartup', 'ShowHomeButton', 'InternetExplorerIntegrationSiteList')
111-
112-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\microsoft_edge~Policy~microsoft_edge~Startup'
113-
RemoveHijackKey 'HKLM:\SOFTWARE\Policies\Microsoft\Edge\RestoreOnStartupURLs'
114-
RemoveHijackKey 'HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Policies\Microsoft\Edge\RestoreOnStartupURLs'
115-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\microsoft_edge~Policy~microsoft_edge_recommended~Startup_recommended'
116-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\microsoft_edge~Policy~microsoft_edge~Startup'
117-
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\Providers\89FA9032-04AF-4BA8-BD43-936A846F7EFE\default\Device\microsoft_edge~Policy~microsoft_edge~Startup'
118-
119-
# Firefox
120-
RemoveHijackKey 'HKCU:\SOFTWARE\Policies\Mozilla\Firefox\Homepage'
82+
if ($PSCmdlet.ParameterSetName -eq 'Install')
83+
{
84+
RegisterTask
85+
return
86+
}
87+
88+
if ($PSCmdlet.ParameterSetName -eq 'Uninstall')
89+
{
90+
UnregisterTask
91+
return
92+
}
93+
94+
# fix it now!
95+
96+
# Chrome
97+
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
98+
RemoveHijack 'HKLM:\SOFTWARE\Policies\Google\Chrome' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
99+
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome\Recommended' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
100+
RemoveHijack 'HKLM:\SOFTWARE\Policies\Google\Chrome\Recommended' @('HomePageLocation', 'RestoreOnStartup', 'ShowHomeButton')
101+
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs' @('HomepageLocation')
102+
RemoveHijack 'HKCU:\SOFTWARE\Policies\Google\Chrome\Recommended\RestoreOnStartupURLs' @('HomepageLocation')
103+
104+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Chrome~Policy~googlechrome~Startup'
105+
RemoveHijackKey 'HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs'
106+
RemoveHijackKey 'HKLM:\SOFTWARE\WOW6432Node\Policies\Google\Chrome\RestoreOnStartupURLs'
107+
RemoveHijackKey 'HKLM:\SOFTWARE\WOW6432Node\Policies\Google\Chrome\Recommended\RestoreOnStartupURLs'
108+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\Chrome~Policy~googlechrome_recommended~Startup_recommended'
109+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\Chrome~Policy~googlechrome~Startup'
110+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\Providers\89FA9032-04AF-4BA8-BD43-936A846F7EFE\default\Device\Chrome~Policy~googlechrome~Startup'
111+
112+
# Edge
113+
RemoveHijack 'HKCU:\SOFTWARE\Policies\Microsoft\Edge\Recommended' @('HomepageLocation', 'RestoreOnStartup', 'ShowHomeButton', 'InternetExplorerIntegrationSiteList')
114+
RemoveHijack 'HKCU:\SOFTWARE\Policies\Microsoft\Edge\Internet Settings' @('ProvisionedHomePages')
115+
RemoveHijack 'HKLM:\SOFTWARE\Policies\Microsoft\Edge' @('HomepageLocation', 'RestoreOnStartup', 'ShowHomeButton', 'InternetExplorerIntegrationSiteList')
116+
117+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\microsoft_edge~Policy~microsoft_edge~Startup'
118+
RemoveHijackKey 'HKLM:\SOFTWARE\Policies\Microsoft\Edge\RestoreOnStartupURLs'
119+
RemoveHijackKey 'HKLM:\SOFTWARE\WOW6432Node\Policies\Microsoft\Policies\Microsoft\Edge\RestoreOnStartupURLs'
120+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\microsoft_edge~Policy~microsoft_edge_recommended~Startup_recommended'
121+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\AdmxDefault\89FA9032-04AF-4BA8-BD43-936A846F7EFE\microsoft_edge~Policy~microsoft_edge~Startup'
122+
RemoveHijackKey 'HKLM:\SOFTWARE\Microsoft\PolicyManager\Providers\89FA9032-04AF-4BA8-BD43-936A846F7EFE\default\Device\microsoft_edge~Policy~microsoft_edge~Startup'
123+
124+
# Firefox
125+
RemoveHijackKey 'HKCU:\SOFTWARE\Policies\Mozilla\Firefox\Homepage'
121126
}

0 commit comments

Comments
 (0)