Update remove.py

This commit is contained in:
Sean 2023-02-06 14:18:37 -06:00 committed by GitHub
commit 688548fe6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,42 +83,3 @@ else:
subprocess.run(f'takeown /f "{f.path}" > NUL 2>&1', shell=True)
subprocess.run(f'icacls "{f.path}" /inheritance:e /grant "{user_name}:(OI)(CI)F" /T /C > NUL 2>&1', shell=True)
os.remove(f.path)
##
## Disable Edge app in registry HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\EndOfLife\
##
# Current sser's SID
def get_current_user_sid():
sid = ctypes.c_char_p()
size = ctypes.c_int()
ctypes.windll.advapi32.GetUserNameA(None, ctypes.byref(size))
name = ctypes.create_string_buffer(size.value + 1)
ctypes.windll.advapi32.GetUserNameA(name, ctypes.byref(size))
user_name = name.value.decode("utf-8")
command = f'wmic useraccount where name="{user_name}" get sid'
result = subprocess.run(command, stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8')
return result.strip().split("\n")[1]
#Find installed Edge apps
def find_edge_apps():
command = 'Get-AppxPackage | Where-Object {$_.Name -like "*microsoftedge*"} | Select-Object PackageFullName'
result = subprocess.run(['powershell.exe', command], stdout=subprocess.PIPE).stdout.decode('utf-8')
apps = result.strip().split("\n")[1:]
return [app.strip() for app in apps if "Edge" in app]
#Build the registry key
def add_registry_key(sid, package):
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\EndOfLife")
subkey = winreg.CreateKey(key, sid)
winreg.SetValueEx(subkey, package, 0, winreg.REG_SZ, "")
winreg.CloseKey(subkey)
winreg.CloseKey(key)
#Add the key(s)
sid = get_current_user_sid().strip()
apps = find_edge_apps()
for app in apps:
full_key = f"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Appx\\AppxAllUserStore\\EndOfLife\\{sid}\\{app}"
add_registry_key(sid, app)