A lot of things

This commit is contained in:
2025-10-28 19:02:19 +01:00
parent 393ef60c82
commit 47cff5e7f6
21 changed files with 794 additions and 60 deletions

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A33DF785-C123-48E2-B21E-A229FC8FFB55}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Perfect11.Inbox.UninstallEdge</RootNamespace>
<AssemblyName>Perfect11.Inbox.UninstallEdge</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Tweak.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Perfect11.TweaksInterface\Perfect11.TweaksInterface.csproj">
<Project>{b3f8761a-b4b2-4378-9fe8-06bbfc39fce6}</Project>
<Name>Perfect11.TweaksInterface</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Perfect11 Inbox Tweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Vichingo455")]
[assembly: AssemblyProduct("Perfect11")]
[assembly: AssemblyCopyright("Copyright © 2025 Vichingo455")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a33df785-c123-48e2-b21e-a229fc8ffb55")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,322 @@
using Microsoft.Win32;
using Perfect11.TweaksInterface;
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Principal;
namespace Perfect11.Inbox.UninstallEdge
{
public class Tweak : IPlugin
{
public string Name => "Uninstall Microsoft Edge";
public string Description => "Remove Microsoft Edge from the system.";
public string Category => "Apps";
public string Execute()
{
void KillProcessIfRunning(string name)
{
try
{
foreach (var p in Process.GetProcessesByName(name))
{
try { p.Kill(); } catch { }
}
}
catch { }
}
void RunHidden(string fileName, string args)
{
try
{
var psi = new ProcessStartInfo(fileName, args)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = false,
RedirectStandardError = false
};
var p = Process.Start(psi);
p?.WaitForExit();
}
catch { }
}
void TryDeleteRegistryKey(RegistryKey hive, string subKey)
{
try
{
hive.DeleteSubKeyTree(subKey, throwOnMissingSubKey: false);
}
catch
{
}
}
void TryDeleteRegistryValue(RegistryKey hive, string subKey, string valueName)
{
try
{
using (var key = hive.OpenSubKey(subKey, writable: true))
{
key?.DeleteValue(valueName, throwOnMissingValue: false);
}
}
catch { }
}
void TryCreateSetValue(RegistryKey hive, string subKey, string valueName, int dwordValue, bool createIfMissing = true)
{
try
{
if (createIfMissing)
{
using (var key = hive.CreateSubKey(subKey))
{
key?.SetValue(valueName, dwordValue, RegistryValueKind.DWord);
}
}
else
{
using (var key = hive.OpenSubKey(subKey, writable: true))
{
key?.SetValue(valueName, dwordValue, RegistryValueKind.DWord);
}
}
}
catch { }
}
void TryDeleteDirectory(string path)
{
try
{
if (Directory.Exists(path))
Directory.Delete(path, recursive: true);
}
catch
{
TryTakeOwnershipAndDelete(path);
}
}
void TryTakeOwnershipAndDelete(string path)
{
try
{
if (File.Exists(path) || Directory.Exists(path))
{
RunHidden("takeown", $"/f \"{path}\" /a /r /d y");
RunHidden("icacls", $"\"{path}\" /grant Everyone:F /t /c");
try
{
if (File.Exists(path)) File.Delete(path);
else if (Directory.Exists(path)) Directory.Delete(path, true);
}
catch {}
}
}
catch { }
}
void TryDeleteIfExists(string file)
{
try
{
if (File.Exists(file))
File.Delete(file);
}
catch { }
}
string GetCurrentUserSid()
{
try
{
var nt = WindowsIdentity.GetCurrent();
return nt?.User?.Value ?? "";
}
catch { return ""; }
}
string[] RunPowerShellAndGetLines(string command)
{
try
{
var psi = new ProcessStartInfo("powershell", "-NoProfile -Command " + WrapForPowerShell(command))
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var p = Process.Start(psi);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
}
catch
{
return new string[0];
}
}
string WrapForPowerShell(string cmd)
{
return "\"" + cmd.Replace("\"", "\\\"") + "\"";
}
string pf = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string pf86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
bool existsInPf = Directory.Exists(Path.Combine(pf, "Microsoft\\Edge"));
bool existsInPf86 = Directory.Exists(Path.Combine(pf86, "Microsoft\\Edge"));
if (!existsInPf && !existsInPf86)
{
throw new Exception("Microsoft Edge not found.");
}
if (existsInPf86)
{
KillProcessIfRunning("msedge");
KillProcessIfRunning("MicrosoftEdgeUpdate");
KillProcessIfRunning("msedgewebview2");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Edge");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\EdgeIntegration");
RunHidden("net", "stop MicrosoftEdgeElevationService");
RunHidden("sc", "delete MicrosoftEdgeElevationService");
RunHidden("net", "stop edgeupdate");
RunHidden("sc", "delete edgeupdate");
RunHidden("net", "stop edgeupdatem");
RunHidden("sc", "delete edgeupdatem");
TryDeleteDirectory(Path.Combine(pf86, "Microsoft\\Edge"));
TryDeleteDirectory(Path.Combine(pf86, "Microsoft\\EdgeCore"));
TryDeleteDirectory(Path.Combine(pf86, "Microsoft\\EdgeUpdate"));
TryDeleteDirectory(Path.Combine(pf86, "Microsoft\\EdgeWebView"));
TryDeleteDirectory(Path.Combine(pf86, "Microsoft\\Temp"));
TryDeleteDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft\\EdgeUpdate"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\Edge"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\EdgeCore"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\EdgeUpdate"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\EdgeWebView"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\Temp"));
TryCreateSetValue(Registry.LocalMachine, @"Software\Microsoft\EdgeUpdate", "DoNotUpdateToEdgeWithChromium", 1);
TryCreateSetValue(Registry.LocalMachine, @"Software\WOW6432Node\Microsoft\EdgeUpdate", "DoNotUpdateToEdgeWithChromium", 1);
}
else
{
KillProcessIfRunning("msedge");
KillProcessIfRunning("MicrosoftEdgeUpdate");
KillProcessIfRunning("msedgewebview2");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Active Setup\Installed Components\{9459C573-B17A-45AE-9F64-1857B5D58CEE}");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Edge");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Internet Explorer\EdgeIntegration");
RunHidden("net", "stop MicrosoftEdgeElevationService");
RunHidden("sc", "delete MicrosoftEdgeElevationService");
RunHidden("net", "stop edgeupdate");
RunHidden("sc", "delete edgeupdate");
RunHidden("net", "stop edgeupdatem");
RunHidden("sc", "delete edgeupdatem");
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\Edge"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\EdgeCore"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\EdgeUpdate"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\EdgeWebView"));
TryDeleteDirectory(Path.Combine(pf, "Microsoft\\Temp"));
TryCreateSetValue(Registry.LocalMachine, @"Software\Microsoft\EdgeUpdate", "DoNotUpdateToEdgeWithChromium", 1);
}
TryDeleteIfExists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Microsoft Edge.lnk"));
TryDeleteIfExists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), "Microsoft Edge.lnk"));
TryDeleteIfExists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs\\Microsoft Edge.lnk"));
TryDeleteIfExists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs\\Microsoft Edge.lnk"));
TryDeleteIfExists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar\\Microsoft Edge.lnk"));
var systemTasksPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32", "Tasks");
try
{
foreach (var f in Directory.EnumerateFiles(systemTasksPath, "*MicrosoftEdge*", SearchOption.AllDirectories))
{
TryTakeOwnershipAndDelete(f);
}
}
catch {}
string userSid = GetCurrentUserSid();
try
{
string psListCmd = "Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -like '*microsoftedge*' } | Select-Object -ExpandProperty PackageFullName";
var edgePackages = RunPowerShellAndGetLines(psListCmd);
foreach (var pkg in edgePackages)
{
if (string.IsNullOrWhiteSpace(pkg)) continue;
string packageName = pkg.Trim();
if (!string.IsNullOrEmpty(userSid))
{
TryCreateSetValue(Registry.LocalMachine, $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\EndOfLife\{userSid}\{packageName}", "", 0, createIfMissing: true);
TryCreateSetValue(Registry.LocalMachine, $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\EndOfLife\S-1-5-18\{packageName}", "", 0, createIfMissing: true);
TryCreateSetValue(Registry.LocalMachine, $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deprovisioned\{packageName}", "", 0, createIfMissing: true);
}
RunHidden("powershell", $"-Command \"Remove-AppxPackage -Package '{packageName}'\" 2>$null");
RunHidden("powershell", $"-Command \"Remove-AppxPackage -Package '{packageName}' -AllUsers\" 2>$null");
}
}
catch {}
try
{
var sysRoot = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
foreach (var f in Directory.EnumerateFiles(sysRoot, "Microsoft.MicrosoftEdge*", SearchOption.AllDirectories))
{
TryTakeOwnershipAndDelete(f);
}
}
catch { }
try
{
foreach (var f in Directory.EnumerateFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32"), "MicrosoftEdge*.exe", SearchOption.AllDirectories))
{
TryTakeOwnershipAndDelete(f);
}
}
catch { }
try
{
foreach (var f in Directory.EnumerateFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SysWOW64"), "MicrosoftEdge*.exe", SearchOption.AllDirectories))
{
TryTakeOwnershipAndDelete(f);
}
}
catch { }
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\Clients\StartMenuInternet\Microsoft Edge");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\RegisteredApplications", "Microsoft Edge");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.htm\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.html\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.mht\OpenWithProgIds", "MSEdgeMHT");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.mhtml\OpenWithProgIds", "MSEdgeMHT");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.pdf\OpenWithProgIds", "MSEdgePDF");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.shtml\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.svg\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.webp\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.xht\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.xhtml\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\Classes\.xml\OpenWithProgIds", "MSEdgeHTM");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Clients\StartMenuInternet\Microsoft Edge");
TryDeleteRegistryValue(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\RegisteredApplications", "Microsoft Edge");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Edge");
TryDeleteRegistryKey(Registry.LocalMachine, @"SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\EdgeIntegration");
return "Microsoft Edge should now be uninstalled.";
}
}
}