@ -1,7 +1,6 @@
using System ;
using System.Diagnostics ;
using System.IO ;
using System.Linq ;
using System.Security.Principal ;
using System.Threading ;
using amecs.Misc ;
@ -14,6 +13,9 @@ namespace amecs.Actions
{
private static string _mountedPath ;
private static string _winVer ;
private static string _win11Setup = "" ;
private static bool _win11 = Environment . OSVersion . Version . Build > = 2 2 0 0 0 ;
private const string ExplorerPatcherId = "D17F1E1A-5919-4427-8F89-A1A8503CA3EB" ;
public static bool DeAme ( )
{
@ -64,9 +66,7 @@ Continue? (Y/N): "
try
{
if ( ( ( string ) key . OpenSubKey ( item ) . GetValue ( "DisplayName" ) ) . Equals ( "Open-Shell" ) )
{
openShellId = item ;
}
}
catch
{
@ -78,8 +78,7 @@ Continue? (Y/N): "
{
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nUninstalling Open-Shell..." ) ;
var proc = Process . Start ( "MsiExec.exe" , $"/X{openShellId} /quiet" ) ;
proc . WaitForExit ( ) ;
Process . Start ( "MsiExec.exe" , $"/X{openShellId} /quiet" ) ? . WaitForExit ( ) ;
if ( userSid ! = null )
{
@ -93,10 +92,63 @@ Continue? (Y/N): "
var epSetupPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ExplorerPatcher\ep_setup.exe" ;
if ( File . Exists ( epSetupPath ) )
{
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nUninstalling ExplorerPatcher, you'll need to click the prompts..." ) ;
var proc = Process . Start ( epSetupPath , $"/uninstall" ) ;
proc . WaitForExit ( ) ;
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nUninstalling ExplorerPatcher..." ) ;
var winlogon = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" , true ) ;
winlogon ? . SetValue ( "AutoRestartShell" , 0 ) ;
// kill processes that the files use
foreach ( var processName in new [ ] { "explorer.exe" , "rundll32.exe" , "dllhost.exe" , "ShellExperienceHost.exe" , "StartMenuExperienceHost.exe" } )
{
foreach ( var process in Process . GetProcessesByName ( Path . GetFileNameWithoutExtension ( processName ) ) )
{
process . Kill ( ) ;
process . WaitForExit ( ) ;
}
}
// delete DWM service that removes rounded corners
Process . Start ( "sc" , $"stop \" ep_dwm_ { ExplorerPatcherId } \ "" ) ? . WaitForExit ( ) ;
Process . Start ( "sc" , $"delete \" ep_dwm_ { ExplorerPatcherId } \ "" ) ? . WaitForExit ( ) ;
// remove registered DLL
var explorerPatcherDllPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) , "ExplorerPatcher" , "ExplorerPatcher.amd64.dll" ) ;
Process . Start ( "regsvr32.exe" , $"/s /u \" { explorerPatcherDllPath } \ "" ) ? . WaitForExit ( ) ;
// delete files
foreach ( var file in new [ ]
{
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
@"SystemApps\ShellExperienceHost_cw5n1h2txyewy\dxgi.dll" ) ,
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
@"SystemApps\ShellExperienceHost_cw5n1h2txyewy\wincorlib.dll" ) ,
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
@"SystemApps\ShellExperienceHost_cw5n1h2txyewy\wincorlib_orig.dll" ) ,
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
@"SystemApps\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\dxgi.dll" ) ,
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
@"SystemApps\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\wincorlib.dll" ) ,
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
@"SystemApps\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\wincorlib_orig.dll" ) ,
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ,
"dxgi.dll" )
} )
{
if ( File . Exists ( file ) ) File . Delete ( file ) ;
}
foreach ( var folder in new [ ]
{
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ,
"ExplorerPatcher" ) ,
Path . Combine (
Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) ,
@"Microsoft\Windows\Start Menu\Programs\ExplorerPatcher" )
} )
{
if ( Directory . Exists ( folder ) ) Directory . Delete ( folder , true ) ;
}
winlogon ? . SetValue ( "AutoRestartShell" , 1 ) ;
}
Program . Frame . Clear ( ) ;
@ -111,25 +163,18 @@ Continue? (Y/N): "
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nContinuing without uninstalling software...\r\n" ) ;
}
// ExplorerPatcher re-opens Explorer as SYSTEM after uninstalling, so it has to be restarted
// no silent uninstall is available, so user has to manually click 'Yes' to uninstall
// https://github.com/valinet/ExplorerPatcher/discussions/2007
Thread . Sleep ( 5 0 0 ) ;
var winlogon = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" , true ) ;
winlogon . SetValue ( "AutoRestartShell" , 0 ) ;
foreach ( var exp in Process . GetProcessesByName ( "explorer" ) )
{
exp . Kill ( ) ;
}
winlogon . SetValue ( "AutoRestartShell" , 1 ) ;
NSudo . RunProcessAsUser ( NSudo . GetUserToken ( ) , "explorer.exe" , "" , 0 ) ;
// all policies are cleared as a user that's de-ameliorating is unlikely
// to have their own policies in the first place
// restart Explorer
if ( Process . GetProcessesByName ( "explorer" ) . Length = = 0 )
NSudo . RunProcessAsUser ( NSudo . GetUserToken ( ) , "explorer.exe" , "" , 0 ) ;
// all policies are cleared as a user that's de-ameliorating is unlikely to have their own policies in the first place
// also clear ExplorerPatcher Registry entries
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nClearing policies..." ) ;
foreach ( var keyPath in new [ ] {
$@"HKU\{userSid}\Software\Microsoft\Windows\CurrentVersion\Policies" ,
$@"HKU\{userSid}\Software\Policies" ,
$@"HKU\{userSid}\Software\ExplorerPatcher" ,
$@"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{{{ExplorerPatcherId}}}_ExplorerPatcher" ,
@"HKLM\Software\Microsoft\Windows\CurrentVersion\Policies" ,
@"HKLM\Software\Policies" ,
@"HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Policies"
@ -156,20 +201,23 @@ Continue? (Y/N): "
key . Close ( ) ;
}
Thread . Sleep ( 3 0 0 0 ) ;
Program . Frame . Clear ( ) ;
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nCompleted initial setup!" , ConsoleColor . Green ) ;
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nWindows Setup will display as 'Windows Server,' but it's not actually installing Windows Server and is only set as such to bypass hardware requirements." ) ;
Console . WriteLine ( ) ;
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nWaiting 10 seconds and starting..." ) ;
if ( _win11 )
{
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nWindows Setup will display as 'Windows Server,' but it's not actually installing Windows Server and is only set as such to bypass hardware requirements." ) ;
Console . WriteLine ( ) ;
}
ConsoleTUI . OpenFrame . WriteCentered ( "\r\nWaiting 10 seconds and starting Windows Setup..." ) ;
Console . ForegroundColor = fc ;
Thread . Sleep ( 1 0 0 0 0 ) ;
Console . WriteLine ( ) ;
try
{
Process . Start ( Path . Combine ( _mountedPath , "setup.exe" ) , "/Auto Upgrade /DynamicUpdate Disable /Product Server" ) ;
if ( _win11 ) _win11Setup = "/Product Server" ;
Process . Start ( Path . Combine ( _mountedPath , "setup.exe" ) , $"/Auto Upgrade /DynamicUpdate Disable {_win11Setup}" ) ;
} catch ( Exception e )
{
ConsoleTUI . OpenFrame . Close (