@@ -31,13 +31,17 @@ param (
3131 [switch ]$KeepAppX
3232)
3333
34- $version = ' 1.7'
34+ $sys32 = [Environment ]::GetFolderPath(' System' )
35+ $env: path = " $ ( [Environment ]::GetFolderPath(' Windows' )) ;$sys32 ;$sys32 \Wbem;$sys32 \WindowsPowerShell\v1.0;" + $env: path
36+
37+ $version = ' 1.8'
3538$host.UI.RawUI.WindowTitle = " EdgeRemover $version | made by @he3als"
3639
3740# credit to ave9858 for Edge removal method: https://gist.github.com/ave9858/c3451d9f452389ac7607c99d45edecc6
3841$ProgressPreference = " SilentlyContinue"
3942$user = $env: USERNAME
4043$SID = (New-Object System.Security.Principal.NTAccount($user )).Translate([Security.Principal.SecurityIdentifier ]).Value
44+ $admin = [System.Security.Principal.NTAccount ]$ (New-Object System.Security.Principal.SecurityIdentifier(' S-1-5-32-544' )).Translate([System.Security.Principal.NTAccount ]).Value
4145$EdgeRemoverReg = ' HKLM:\SOFTWARE\EdgeRemover'
4246
4347if ($Exit -and ((-not $UninstallAll ) -and (-not $UninstallEdge ))) {
@@ -142,7 +146,10 @@ function DeleteEdgeUpdate {
142146 }
143147
144148 # delete the edgeupdate folder
145- Remove-Item - Path " $env: SystemDrive \Program Files (x86)\Microsoft\EdgeUpdate" - Recurse - Force | Out-Null
149+ ' LocalApplicationData' , ' ProgramFilesX86' , ' ProgramFiles' | ForEach-Object {
150+ $folder = " $ ( [Environment ]::GetFolderPath($_ )) \Microsoft\EdgeUpdate"
151+ if (Test-Path $folder ) { Remove-Item - Path $folder - Recurse - Force | Out-Null }
152+ }
146153 }
147154
148155 # revert error action preference
@@ -158,7 +165,7 @@ function RemoveEdgeChromium {
158165
159166 # terminate Edge processes
160167 $services = (Get-Service - Name " *edge*" | Where-Object {$_.DisplayName -like " *Microsoft Edge*" }).Name
161- $processes = (Get-Process | Where-Object {($_.Path -like " $env: SystemDrive \Program Files (x86 )\Microsoft\*" ) -or ($_.Name -like " *msedge*" )}).Id
168+ $processes = (Get-Process | Where-Object {($_.Path -like " $ ( [ Environment ]::GetFolderPath( ' ProgramFilesX86 ' ) ) \Microsoft\*" ) -or ($_.Name -like " *msedge*" )}).Id
162169 foreach ($process in $processes ) {
163170 Stop-Process - Id $process - Force
164171 }
@@ -179,15 +186,47 @@ function RemoveEdgeChromium {
179186 }
180187
181188 # allow Edge uninstall
189+ # seems to no longer exist, kept anyways for legacy purposes
190+ # replaced with modifying IntegratedServicesRegionPolicySet.json
182191 $devKeyPath = Join-Path - Path $baseKey - ChildPath " EdgeUpdateDev"
183192 if (-not (Test-Path $devKeyPath )) { New-Item - Path $devKeyPath - ItemType " Key" - Force | Out-Null }
184193 Set-ItemProperty - Path $devKeyPath - Name " AllowUninstall" - Value " " - Type String - Force | Out-Null
185194
195+ # modifies IntegratedServicesRegionPolicySet as that's now checked for Edge uninstall
196+ $integratedServicesPath = " $sys32 \IntegratedServicesRegionPolicySet.json"
197+ if (! (Test-Path $integratedServicesPath )) {
198+ Write-Warning " '$integratedServicesPath ' not found, continuing anyways but uninstall might fail."
199+ } else {
200+ try {
201+ # get perms (normally TI :3)
202+ $acl = Get-Acl - Path $integratedServicesPath
203+ $backup = [System.Security.AccessControl.FileSecurity ]::new()
204+ $backup.SetSecurityDescriptorSddlForm ($acl.Sddl )
205+ # full control
206+ $acl.SetOwner ($admin )
207+ $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($admin , " FullControl" , " Allow" )
208+ $acl.AddAccessRule ($rule )
209+ # set modified ACL
210+ Set-Acl - Path $integratedServicesPath - AclObject $acl
211+
212+ # modify the stuff :3
213+ $integratedServices = Get-Content $integratedServicesPath | ConvertFrom-Json
214+ ($integratedServices.policies | Where-Object { ($_ .' $comment' -like " *Edge*" ) -and ($_ .' $comment' -like " *uninstall*" ) }).defaultState = ' enabled'
215+ $modifiedJson = $integratedServices | ConvertTo-Json - Depth 100
216+
217+ $backupIntegratedServicesPath = " IntegratedServicesRegionPolicySet.json.$ ( [System.IO.Path ]::GetRandomFileName()) "
218+ Rename-Item $integratedServicesPath - NewName $backupIntegratedServicesPath - Force
219+ Set-Content $integratedServicesPath - Value $modifiedJson - Force - Encoding UTF8
220+ } catch {
221+ Write-Error " Failed to modify region policies. $_ "
222+ }
223+ }
224+
186225 # uninstall Edge
187226 $uninstallKeyPath = Join-Path - Path $baseKey - ChildPath " Windows\CurrentVersion\Uninstall\Microsoft Edge"
188227 if (Test-Path $uninstallKeyPath ) {
189228 $uninstallString = (Get-ItemProperty - Path $uninstallKeyPath ).UninstallString + " --force-uninstall"
190- Start-Process cmd.exe " /c $uninstallString " - WindowStyle Hidden 2>&1 | Out-Null
229+ Start-Process - Wait cmd.exe - ArgumentList " /c start /wait `"`" $uninstallString " - WindowStyle Hidden
191230 } else {
192231 $edges = @ (); ' LocalApplicationData' , ' ProgramFilesX86' , ' ProgramFiles' | ForEach-Object {
193232 $folder = [Environment ]::GetFolderPath($_ )
@@ -202,18 +241,25 @@ function RemoveEdgeChromium {
202241 # uninstall Edge with MsiExec (e.g. WinGet installs)
203242 Uninstall-MsiexecAppByName - Name " Microsoft Edge"
204243
244+ # revert IntegratedServicesRegionPolicySet modification
245+ if ($backupIntegratedServicesPath ) {
246+ Remove-Item $integratedServicesPath - Force
247+ Rename-Item $backupIntegratedServicesPath - NewName $integratedServicesPath - Force
248+
249+ # restore old ACL
250+ Set-Acl - Path $integratedServicesPath - AclObject $backup
251+ }
252+
205253 # remove user data
206254 if ($removeData ) {
207- $path = " $env: LOCALAPPDATA \Microsoft\Edge"
255+ $path = " $ ( [ Environment ]::GetFolderPath( ' LocalApplicationData ' ) ) \Microsoft\Edge"
208256 if (Test-Path $path ) {Remove-Item $path - Force - Recurse}
209257 }
210258
211259 # remove Edge shortcut on desktop
212260 # may exist for some people after a proper uninstallation
213- $shortcutPath = " $env: USERPROFILE \Desktop\Microsoft Edge.lnk"
214- if (Test-Path $shortcutPath ) {
215- Remove-Item $shortcutPath - Force
216- }
261+ $shortcutPath = " $ ( [Environment ]::GetFolderPath(' Desktop' )) \Microsoft Edge.lnk"
262+ if (Test-Path $shortcutPath ) { Remove-Item $shortcutPath - Force }
217263
218264 # restart explorer if Copilot is enabled
219265 # this will hide the Copilot button
0 commit comments