@ -0,0 +1,559 @@ | |||
!*.gitkeep | |||
# User-specific files | |||
*.rsuser | |||
*.suo | |||
*.user | |||
*.userosscache | |||
*.sln.docstates | |||
# User-specific files (MonoDevelop/Xamarin Studio) | |||
*.userprefs | |||
# Mono auto generated files | |||
mono_crash.* | |||
# Build results | |||
[Dd]ebug/ | |||
[Dd]ebugPublic/ | |||
[Rr]elease/ | |||
[Rr]eleases/ | |||
x64/ | |||
x86/ | |||
[Ww][Ii][Nn]32/ | |||
[Aa][Rr][Mm]/ | |||
[Aa][Rr][Mm]64/ | |||
bld/ | |||
[Bb]in/ | |||
[Oo]bj/ | |||
[Ll]og/ | |||
[Ll]ogs/ | |||
# Visual Studio 2015/2017 cache/options directory | |||
.vs/ | |||
# Uncomment if you have tasks that create the project's static files in wwwroot | |||
#wwwroot/ | |||
# Visual Studio 2017 auto generated files | |||
Generated\ Files/ | |||
# MSTest test Results | |||
[Tt]est[Rr]esult*/ | |||
[Bb]uild[Ll]og.* | |||
# NUnit | |||
*.VisualState.xml | |||
TestResult.xml | |||
nunit-*.xml | |||
# Build Results of an ATL Project | |||
[Dd]ebugPS/ | |||
[Rr]eleasePS/ | |||
dlldata.c | |||
# Benchmark Results | |||
BenchmarkDotNet.Artifacts/ | |||
# .NET Core | |||
project.lock.json | |||
project.fragment.lock.json | |||
artifacts/ | |||
# ASP.NET Scaffolding | |||
ScaffoldingReadMe.txt | |||
# StyleCop | |||
StyleCopReport.xml | |||
# Files built by Visual Studio | |||
*_i.c | |||
*_p.c | |||
*_h.h | |||
*.ilk | |||
*.meta | |||
*.obj | |||
*.iobj | |||
*.pch | |||
*.pdb | |||
*.ipdb | |||
*.pgc | |||
*.pgd | |||
*.rsp | |||
*.sbr | |||
*.tlb | |||
*.tli | |||
*.tlh | |||
*.tmp | |||
*.tmp_proj | |||
*_wpftmp.csproj | |||
*.log | |||
*.tlog | |||
*.vspscc | |||
*.vssscc | |||
.builds | |||
*.pidb | |||
*.svclog | |||
*.scc | |||
# Chutzpah Test files | |||
_Chutzpah* | |||
# Visual C++ cache files | |||
ipch/ | |||
*.aps | |||
*.ncb | |||
*.opendb | |||
*.opensdf | |||
*.sdf | |||
*.cachefile | |||
*.VC.db | |||
*.VC.VC.opendb | |||
# Visual Studio profiler | |||
*.psess | |||
*.vsp | |||
*.vspx | |||
*.sap | |||
# Visual Studio Trace Files | |||
*.e2e | |||
# TFS 2012 Local Workspace | |||
$tf/ | |||
# Guidance Automation Toolkit | |||
*.gpState | |||
# ReSharper is a .NET coding add-in | |||
_ReSharper*/ | |||
*.[Rr]e[Ss]harper | |||
*.DotSettings.user | |||
# TeamCity is a build add-in | |||
_TeamCity* | |||
# DotCover is a Code Coverage Tool | |||
*.dotCover | |||
# AxoCover is a Code Coverage Tool | |||
.axoCover/* | |||
!.axoCover/settings.json | |||
# Coverlet is a free, cross platform Code Coverage Tool | |||
coverage*.json | |||
coverage*.xml | |||
coverage*.info | |||
# Visual Studio code coverage results | |||
*.coverage | |||
*.coveragexml | |||
# NCrunch | |||
_NCrunch_* | |||
.*crunch*.local.xml | |||
nCrunchTemp_* | |||
# MightyMoose | |||
*.mm.* | |||
AutoTest.Net/ | |||
# Web workbench (sass) | |||
.sass-cache/ | |||
# Installshield output folder | |||
[Ee]xpress/ | |||
# DocProject is a documentation generator add-in | |||
DocProject/buildhelp/ | |||
DocProject/Help/*.HxT | |||
DocProject/Help/*.HxC | |||
DocProject/Help/*.hhc | |||
DocProject/Help/*.hhk | |||
DocProject/Help/*.hhp | |||
DocProject/Help/Html2 | |||
DocProject/Help/html | |||
# Click-Once directory | |||
publish/ | |||
# Publish Web Output | |||
*.[Pp]ublish.xml | |||
*.azurePubxml | |||
# Note: Comment the next line if you want to checkin your web deploy settings, | |||
# but database connection strings (with potential passwords) will be unencrypted | |||
*.pubxml | |||
*.publishproj | |||
# Microsoft Azure Web App publish settings. Comment the next line if you want to | |||
# checkin your Azure Web App publish settings, but sensitive information contained | |||
# in these scripts will be unencrypted | |||
PublishScripts/ | |||
# NuGet Packages | |||
*.nupkg | |||
# NuGet Symbol Packages | |||
*.snupkg | |||
# The packages folder can be ignored because of Package Restore | |||
**/[Pp]ackages/* | |||
# except build/, which is used as an MSBuild target. | |||
!**/[Pp]ackages/build/ | |||
# Uncomment if necessary however generally it will be regenerated when needed | |||
#!**/[Pp]ackages/repositories.config | |||
# NuGet v3's project.json files produces more ignorable files | |||
*.nuget.props | |||
*.nuget.targets | |||
# Nuget personal access tokens and Credentials | |||
nuget.config | |||
# Microsoft Azure Build Output | |||
csx/ | |||
*.build.csdef | |||
# Microsoft Azure Emulator | |||
ecf/ | |||
rcf/ | |||
# Windows Store app package directories and files | |||
AppPackages/ | |||
BundleArtifacts/ | |||
Package.StoreAssociation.xml | |||
_pkginfo.txt | |||
*.appx | |||
*.appxbundle | |||
*.appxupload | |||
# Visual Studio cache files | |||
# files ending in .cache can be ignored | |||
*.[Cc]ache | |||
# but keep track of directories ending in .cache | |||
!?*.[Cc]ache/ | |||
# Others | |||
ClientBin/ | |||
~$* | |||
*~ | |||
*.dbmdl | |||
*.dbproj.schemaview | |||
*.jfm | |||
*.pfx | |||
*.publishsettings | |||
orleans.codegen.cs | |||
# Including strong name files can present a security risk | |||
# (https://github.com/github/gitignore/pull/2483#issue-259490424) | |||
#*.snk | |||
# Since there are multiple workflows, uncomment next line to ignore bower_components | |||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) | |||
#bower_components/ | |||
# RIA/Silverlight projects | |||
Generated_Code/ | |||
# Backup & report files from converting an old project file | |||
# to a newer Visual Studio version. Backup files are not needed, | |||
# because we have git ;-) | |||
_UpgradeReport_Files/ | |||
Backup*/ | |||
UpgradeLog*.XML | |||
UpgradeLog*.htm | |||
ServiceFabricBackup/ | |||
*.rptproj.bak | |||
# SQL Server files | |||
*.mdf | |||
*.ldf | |||
*.ndf | |||
# Business Intelligence projects | |||
*.rdl.data | |||
*.bim.layout | |||
*.bim_*.settings | |||
*.rptproj.rsuser | |||
*- [Bb]ackup.rdl | |||
*- [Bb]ackup ([0-9]).rdl | |||
*- [Bb]ackup ([0-9][0-9]).rdl | |||
# Microsoft Fakes | |||
FakesAssemblies/ | |||
# GhostDoc plugin setting file | |||
*.GhostDoc.xml | |||
# Node.js Tools for Visual Studio | |||
.ntvs_analysis.dat | |||
node_modules/ | |||
# Visual Studio 6 build log | |||
*.plg | |||
# Visual Studio 6 workspace options file | |||
*.opt | |||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) | |||
*.vbw | |||
# Visual Studio LightSwitch build output | |||
**/*.HTMLClient/GeneratedArtifacts | |||
**/*.DesktopClient/GeneratedArtifacts | |||
**/*.DesktopClient/ModelManifest.xml | |||
**/*.Server/GeneratedArtifacts | |||
**/*.Server/ModelManifest.xml | |||
_Pvt_Extensions | |||
# Paket dependency manager | |||
.paket/paket.exe | |||
paket-files/ | |||
# FAKE - F# Make | |||
.fake/ | |||
# CodeRush personal settings | |||
.cr/personal | |||
# Python Tools for Visual Studio (PTVS) | |||
__pycache__/ | |||
*.pyc | |||
# Cake - Uncomment if you are using it | |||
# tools/** | |||
# !tools/packages.config | |||
# Tabs Studio | |||
*.tss | |||
# Telerik's JustMock configuration file | |||
*.jmconfig | |||
# BizTalk build output | |||
*.btp.cs | |||
*.btm.cs | |||
*.odx.cs | |||
*.xsd.cs | |||
# OpenCover UI analysis results | |||
OpenCover/ | |||
# Azure Stream Analytics local run output | |||
ASALocalRun/ | |||
# MSBuild Binary and Structured Log | |||
*.binlog | |||
# NVidia Nsight GPU debugger configuration file | |||
*.nvuser | |||
# MFractors (Xamarin productivity tool) working folder | |||
.mfractor/ | |||
# Local History for Visual Studio | |||
.localhistory/ | |||
# BeatPulse healthcheck temp database | |||
healthchecksdb | |||
# Backup folder for Package Reference Convert tool in Visual Studio 2017 | |||
MigrationBackup/ | |||
# Ionide (cross platform F# VS Code tools) working folder | |||
.ionide/ | |||
# Fody - auto-generated XML schema | |||
FodyWeavers.xsd | |||
# VS Code files for those working on multiple tools | |||
.vscode/* | |||
!.vscode/settings.json | |||
!.vscode/tasks.json | |||
!.vscode/launch.json | |||
!.vscode/extensions.json | |||
*.code-workspace | |||
# Local History for Visual Studio Code | |||
.history/ | |||
# Windows Installer files from build outputs | |||
*.cab | |||
*.msi | |||
*.msix | |||
*.msm | |||
*.msp | |||
# JetBrains Rider | |||
.idea/ | |||
*.sln.iml | |||
### Git ### | |||
# Created by git for backups. To disable backups in Git: | |||
# $ git config --global mergetool.keepBackup false | |||
*.orig | |||
# Created by git when using merge tools for conflicts | |||
*.BACKUP.* | |||
*.BASE.* | |||
*.LOCAL.* | |||
*.REMOTE.* | |||
*_BACKUP_*.txt | |||
*_BASE_*.txt | |||
*_LOCAL_*.txt | |||
*_REMOTE_*.txt | |||
### vs ### | |||
# User-specific files | |||
# User-specific files (MonoDevelop/Xamarin Studio) | |||
# Mono auto generated files | |||
# Build results | |||
# Visual Studio 2015/2017 cache/options directory | |||
# Uncomment if you have tasks that create the project's static files in wwwroot | |||
# Visual Studio 2017 auto generated files | |||
# MSTest test Results | |||
# NUnit | |||
# Build Results of an ATL Project | |||
# Benchmark Results | |||
# .NET Core | |||
# StyleCop | |||
# Files built by Visual Studio | |||
# Chutzpah Test files | |||
# Visual C++ cache files | |||
# Visual Studio profiler | |||
# Visual Studio Trace Files | |||
# TFS 2012 Local Workspace | |||
# Guidance Automation Toolkit | |||
# ReSharper is a .NET coding add-in | |||
# TeamCity is a build add-in | |||
# DotCover is a Code Coverage Tool | |||
# AxoCover is a Code Coverage Tool | |||
# Coverlet is a free, cross platform Code Coverage Tool | |||
coverage*[.json, .xml, .info] | |||
# Visual Studio code coverage results | |||
# NCrunch | |||
# MightyMoose | |||
# Web workbench (sass) | |||
# Installshield output folder | |||
# DocProject is a documentation generator add-in | |||
# Click-Once directory | |||
# Publish Web Output | |||
# Note: Comment the next line if you want to checkin your web deploy settings, | |||
# but database connection strings (with potential passwords) will be unencrypted | |||
# Microsoft Azure Web App publish settings. Comment the next line if you want to | |||
# checkin your Azure Web App publish settings, but sensitive information contained | |||
# in these scripts will be unencrypted | |||
# NuGet Packages | |||
# NuGet Symbol Packages | |||
# The packages folder can be ignored because of Package Restore | |||
# except build/, which is used as an MSBuild target. | |||
# Uncomment if necessary however generally it will be regenerated when needed | |||
# NuGet v3's project.json files produces more ignorable files | |||
# Microsoft Azure Build Output | |||
# Microsoft Azure Emulator | |||
# Windows Store app package directories and files | |||
# Visual Studio cache files | |||
# files ending in .cache can be ignored | |||
# but keep track of directories ending in .cache | |||
# Others | |||
# Including strong name files can present a security risk | |||
# (https://github.com/github/gitignore/pull/2483#issue-259490424) | |||
# Since there are multiple workflows, uncomment next line to ignore bower_components | |||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) | |||
# RIA/Silverlight projects | |||
# Backup & report files from converting an old project file | |||
# to a newer Visual Studio version. Backup files are not needed, | |||
# because we have git ;-) | |||
# SQL Server files | |||
# Business Intelligence projects | |||
# Microsoft Fakes | |||
# GhostDoc plugin setting file | |||
# Node.js Tools for Visual Studio | |||
# Visual Studio 6 build log | |||
# Visual Studio 6 workspace options file | |||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) | |||
# Visual Studio LightSwitch build output | |||
# Paket dependency manager | |||
# FAKE - F# Make | |||
# CodeRush personal settings | |||
# Python Tools for Visual Studio (PTVS) | |||
# Cake - Uncomment if you are using it | |||
# tools/** | |||
# !tools/packages.config | |||
# Tabs Studio | |||
# Telerik's JustMock configuration file | |||
# BizTalk build output | |||
# OpenCover UI analysis results | |||
# Azure Stream Analytics local run output | |||
# MSBuild Binary and Structured Log | |||
# NVidia Nsight GPU debugger configuration file | |||
# MFractors (Xamarin productivity tool) working folder | |||
# Local History for Visual Studio | |||
# BeatPulse healthcheck temp database | |||
# Backup folder for Package Reference Convert tool in Visual Studio 2017 | |||
# Ionide (cross platform F# VS Code tools) working folder |
@ -0,0 +1,132 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Diagnostics; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Runtime.InteropServices; | |||
using System.Security; | |||
using System.Text; | |||
using System.Threading; | |||
using amecs.Misc; | |||
using Ameliorated.ConsoleUtils; | |||
using Microsoft.Dism; | |||
namespace amecs.Actions | |||
{ | |||
public class _NET | |||
{ | |||
private static string _mountedPath; | |||
private static string _isoPath; | |||
private static void Unmount() | |||
{ | |||
if (_isoPath == "none") | |||
return; | |||
SelectWindowsImage.DismountIso(_isoPath); | |||
} | |||
public static bool Install() | |||
{ | |||
(_mountedPath, _isoPath, _, _, _) = SelectWindowsImage.GetMediaPath(true); | |||
if (_mountedPath == null) return false; | |||
if (!Directory.Exists(_mountedPath + @"\sources\sxs") || !Directory.GetFiles(_mountedPath + @"\sources\sxs", "*netfx3*").Any()) | |||
{ | |||
Unmount(); | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("ISO/USB/folder does not contain the required files.", | |||
ConsoleColor.Red, Console.BackgroundColor, new ChoicePrompt() { AnyKey = true, Text = "Press any key to return to the Menu: " }); | |||
return false; | |||
} | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nInstalling .NET 3.5"); | |||
var topCache = Console.CursorTop; | |||
var leftCache = Console.CursorLeft; | |||
Console.WriteLine(); | |||
var inProgress = false; | |||
try | |||
{ | |||
using var indicator = new ConsoleUtils.LoadingIndicator(); | |||
DismApi.Initialize(DismLogLevel.LogErrors); | |||
using (var session = DismApi.OpenOnlineSession()) | |||
{ | |||
var stdout = GetStdHandle(-11); | |||
var indicatorStopped = false; | |||
var maxHashTags = (ConsoleTUI.OpenFrame.DisplayWidth - 5); | |||
DismApi.EnableFeatureByPackagePath(session, "NetFX3", null, true, true, new List<string>() { _mountedPath + @"\sources\sxs" }, delegate(DismProgress progress) | |||
{ | |||
inProgress = true; | |||
if (!indicatorStopped) | |||
{ | |||
indicator.Stop(); | |||
Console.SetCursorPosition(leftCache, topCache); | |||
Console.WriteLine(" "); | |||
} | |||
indicatorStopped = true; | |||
var progressPercentage = progress.Current / 10; | |||
var currentHashTags = (int)Math.Ceiling(Math.Min(((double)progressPercentage / 100) * maxHashTags, maxHashTags)); | |||
var spaces = maxHashTags - currentHashTags + (4 - progressPercentage.ToString().Length); | |||
var sb = new StringBuilder(new string('#', currentHashTags) + new string(' ', spaces) + progressPercentage + "%"); | |||
WriteConsoleOutputCharacter(stdout, sb, (uint)sb.Length, new Languages.COORD((short)ConsoleTUI.OpenFrame.DisplayOffset, (short)Console.CursorTop), out _); | |||
inProgress = false; | |||
}); | |||
session.Close(); | |||
Thread.Sleep(100); | |||
var sb = new StringBuilder(new string('#', maxHashTags) + " 100%"); | |||
uint throwaway; | |||
WriteConsoleOutputCharacter(stdout, sb, (uint)sb.Length, new Languages.COORD((short)ConsoleTUI.OpenFrame.DisplayOffset, (short)Console.CursorTop), out throwaway); | |||
} | |||
DismApi.Shutdown(); | |||
Unmount(); | |||
} catch (Exception e) | |||
{ | |||
while (inProgress) | |||
{ | |||
Thread.Sleep(50); | |||
} | |||
Unmount(); | |||
Console.WriteLine(); | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("DISM error: " + e.Message, ConsoleColor.Red, Console.BackgroundColor, new ChoicePrompt() | |||
{ | |||
AnyKey = true, | |||
Text = "Press any key to return to the Menu: " | |||
}); | |||
return false; | |||
} | |||
Console.WriteLine(); | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close(".NET 3.5 installed successfully", ConsoleColor.Green, Console.BackgroundColor, new ChoicePrompt() | |||
{ | |||
AnyKey = true, | |||
Text = "Press any key to return to the Menu: " | |||
}); | |||
return true; | |||
} | |||
[StructLayout(LayoutKind.Sequential)] | |||
public struct COORD | |||
{ | |||
public short X; | |||
public short Y; | |||
public COORD(short X, short Y) | |||
{ | |||
this.X = X; | |||
this.Y = Y; | |||
} | |||
}; | |||
[DllImport("kernel32.dll", SetLastError = true)] | |||
internal static extern bool WriteConsoleOutputCharacter(IntPtr hConsoleOutput, StringBuilder lpCharacter, uint nLength, Languages.COORD dwWriteCoord, out uint lpNumberOfCharsWritten); | |||
[DllImport("kernel32.dll", SetLastError = true)] | |||
static extern IntPtr GetStdHandle(int nStdHandle); | |||
} | |||
} |
@ -0,0 +1,313 @@ | |||
using System; | |||
using System.DirectoryServices.AccountManagement; | |||
using System.Runtime.InteropServices; | |||
using System.Text; | |||
using System.Threading; | |||
using Ameliorated.ConsoleUtils; | |||
namespace amecs.Actions | |||
{ | |||
public class AutoLogon | |||
{ | |||
internal static class SafeNativeMethods | |||
{ | |||
#region Structures | |||
[StructLayout(LayoutKind.Sequential)] | |||
public struct LSA_UNICODE_STRING : IDisposable | |||
{ | |||
public UInt16 Length; | |||
public UInt16 MaximumLength; | |||
public IntPtr Buffer; | |||
public void Dispose() | |||
{ | |||
this = new LSA_UNICODE_STRING(); | |||
} | |||
} | |||
public struct LSA_OBJECT_ATTRIBUTES | |||
{ | |||
public int Length; | |||
public IntPtr RootDirectory; | |||
public LSA_UNICODE_STRING ObjectName; | |||
public UInt32 Attributes; | |||
public IntPtr SecurityDescriptor; | |||
public IntPtr SecurityQualityOfService; | |||
} | |||
public enum LSA_AccessPolicy : long | |||
{ | |||
POLICY_VIEW_LOCAL_INFORMATION = 0x00000001L, | |||
POLICY_VIEW_AUDIT_INFORMATION = 0x00000002L, | |||
POLICY_GET_PRIVATE_INFORMATION = 0x00000004L, | |||
POLICY_TRUST_ADMIN = 0x00000008L, | |||
POLICY_CREATE_ACCOUNT = 0x00000010L, | |||
POLICY_CREATE_SECRET = 0x00000020L, | |||
POLICY_CREATE_PRIVILEGE = 0x00000040L, | |||
POLICY_SET_DEFAULT_QUOTA_LIMITS = 0x00000080L, | |||
POLICY_SET_AUDIT_REQUIREMENTS = 0x00000100L, | |||
POLICY_AUDIT_LOG_ADMIN = 0x00000200L, | |||
POLICY_SERVER_ADMIN = 0x00000400L, | |||
POLICY_LOOKUP_NAMES = 0x00000800L, | |||
POLICY_NOTIFICATION = 0x00001000L | |||
} | |||
#endregion | |||
#region DLL Imports | |||
[DllImport("advapi32")] | |||
public static extern IntPtr FreeSid(IntPtr pSid); | |||
[DllImport("advapi32.dll", PreserveSig = true)] | |||
public static extern UInt32 LsaOpenPolicy( | |||
ref LSA_UNICODE_STRING SystemName, | |||
ref LSA_OBJECT_ATTRIBUTES ObjectAttributes, | |||
Int32 DesiredAccess, | |||
out IntPtr PolicyHandle); | |||
[DllImport("advapi32.dll", SetLastError = true, PreserveSig = true)] | |||
public static extern uint LsaStorePrivateData( | |||
IntPtr PolicyHandle, | |||
LSA_UNICODE_STRING[] KeyName, | |||
LSA_UNICODE_STRING[] PrivateData); | |||
[DllImport("advapi32.dll", PreserveSig = true)] | |||
public static extern uint LsaRetrievePrivateData( | |||
IntPtr PolicyHandle, | |||
LSA_UNICODE_STRING[] KeyName, | |||
out IntPtr PrivateData); | |||
[DllImport("advapi32.dll", PreserveSig = true)] | |||
public static extern uint LsaNtStatusToWinError(uint status); | |||
[DllImport("advapi32.dll")] | |||
public static extern uint LsaClose(IntPtr ObjectHandle); | |||
#endregion | |||
} | |||
#region Functions | |||
/// <summary> | |||
/// Store Encrypted Data | |||
/// </summary> | |||
/// <param name="keyName"></param> | |||
/// <param name="Data"></param> | |||
/// <returns></returns> | |||
public static long StoreData(String keyName, String Data) | |||
{ | |||
long winErrorCode = 0; | |||
IntPtr sid = IntPtr.Zero; | |||
int sidSize = 0; | |||
//allocate buffers | |||
sid = Marshal.AllocHGlobal(sidSize); | |||
//initialize an empty unicode-string | |||
SafeNativeMethods.LSA_UNICODE_STRING systemName = new SafeNativeMethods.LSA_UNICODE_STRING(); | |||
//Set desired access rights (requested rights) | |||
int access = (int)(SafeNativeMethods.LSA_AccessPolicy.POLICY_CREATE_SECRET); | |||
//initialize a pointer for the policy handle | |||
IntPtr policyHandle = IntPtr.Zero; | |||
//these attributes are not used, but LsaOpenPolicy wants them to exists | |||
SafeNativeMethods.LSA_OBJECT_ATTRIBUTES ObjectAttributes = new SafeNativeMethods.LSA_OBJECT_ATTRIBUTES(); | |||
ObjectAttributes.Length = 0; | |||
ObjectAttributes.RootDirectory = IntPtr.Zero; | |||
ObjectAttributes.Attributes = 0; | |||
ObjectAttributes.SecurityDescriptor = IntPtr.Zero; | |||
ObjectAttributes.SecurityQualityOfService = IntPtr.Zero; | |||
//get a policy handle | |||
uint resultPolicy = SafeNativeMethods.LsaOpenPolicy(ref systemName, ref ObjectAttributes, access, out policyHandle); | |||
winErrorCode = SafeNativeMethods.LsaNtStatusToWinError(resultPolicy); | |||
if (winErrorCode != 0) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCenteredLine("OpenPolicy failed: " + winErrorCode); | |||
} | |||
else | |||
{ | |||
//initialize an unicode-string for the keyName | |||
SafeNativeMethods.LSA_UNICODE_STRING[] uKeyName = new SafeNativeMethods.LSA_UNICODE_STRING[1]; | |||
uKeyName[0] = new SafeNativeMethods.LSA_UNICODE_STRING(); | |||
uKeyName[0].Buffer = Marshal.StringToHGlobalUni(keyName); | |||
uKeyName[0].Length = (UInt16)(keyName.Length * UnicodeEncoding.CharSize); | |||
uKeyName[0].MaximumLength = (UInt16)((keyName.Length + 1) * UnicodeEncoding.CharSize); | |||
//initialize an unicode-string for the Data to encrypt | |||
SafeNativeMethods.LSA_UNICODE_STRING[] uData = new SafeNativeMethods.LSA_UNICODE_STRING[1]; | |||
uData[0] = new SafeNativeMethods.LSA_UNICODE_STRING(); | |||
uData[0].Buffer = Marshal.StringToHGlobalUni(Data); | |||
uData[0].Length = (UInt16)(Data.Length * UnicodeEncoding.CharSize); | |||
uData[0].MaximumLength = (UInt16)((Data.Length + 1) * UnicodeEncoding.CharSize); | |||
//Store Encrypted Data: | |||
SafeNativeMethods.LsaStorePrivateData(policyHandle, uKeyName, uData); | |||
//winErrorCode = LsaNtStatusToWinError(res); | |||
if (winErrorCode != 0) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCenteredLine("LsaStorePrivateData failed: " + winErrorCode); | |||
} | |||
SafeNativeMethods.LsaClose(policyHandle); | |||
} | |||
SafeNativeMethods.FreeSid(sid); | |||
return winErrorCode; | |||
} | |||
/// <summary> | |||
/// Retrieve Encrypted Data | |||
/// </summary> | |||
/// <param name="keyName"></param> | |||
/// <returns></returns> | |||
public static string RetrieveData(String keyName) | |||
{ | |||
string sout = ""; | |||
long winErrorCode = 0; | |||
IntPtr sid = IntPtr.Zero; | |||
int sidSize = 0; | |||
//allocate buffers | |||
sid = Marshal.AllocHGlobal(sidSize); | |||
//initialize an empty unicode-string | |||
SafeNativeMethods.LSA_UNICODE_STRING systemName = new SafeNativeMethods.LSA_UNICODE_STRING(); | |||
//Set desired access rights (requested rights) | |||
int access = (int)(SafeNativeMethods.LSA_AccessPolicy.POLICY_CREATE_SECRET); | |||
//initialize a pointer for the policy handle | |||
IntPtr policyHandle = IntPtr.Zero; | |||
//these attributes are not used, but LsaOpenPolicy wants them to exists | |||
SafeNativeMethods.LSA_OBJECT_ATTRIBUTES ObjectAttributes = new SafeNativeMethods.LSA_OBJECT_ATTRIBUTES(); | |||
ObjectAttributes.Length = 0; | |||
ObjectAttributes.RootDirectory = IntPtr.Zero; | |||
ObjectAttributes.Attributes = 0; | |||
ObjectAttributes.SecurityDescriptor = IntPtr.Zero; | |||
ObjectAttributes.SecurityQualityOfService = IntPtr.Zero; | |||
//get a policy handle | |||
uint resultPolicy = SafeNativeMethods.LsaOpenPolicy(ref systemName, ref ObjectAttributes, access, out policyHandle); | |||
winErrorCode = SafeNativeMethods.LsaNtStatusToWinError(resultPolicy); | |||
if (winErrorCode != 0) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCenteredLine("OpenPolicy failed: " + winErrorCode); | |||
} | |||
else | |||
{ | |||
//initialize an unicode-string for the keyName | |||
SafeNativeMethods.LSA_UNICODE_STRING[] uKeyName = new SafeNativeMethods.LSA_UNICODE_STRING[1]; | |||
uKeyName[0] = new SafeNativeMethods.LSA_UNICODE_STRING(); | |||
uKeyName[0].Buffer = Marshal.StringToHGlobalUni(keyName); | |||
uKeyName[0].Length = (UInt16)(keyName.Length * UnicodeEncoding.CharSize); | |||
uKeyName[0].MaximumLength = (UInt16)((keyName.Length + 1) * UnicodeEncoding.CharSize); | |||
//Store Encrypted Data: | |||
IntPtr pData; | |||
long result = SafeNativeMethods.LsaRetrievePrivateData(policyHandle, uKeyName, out pData); | |||
//winErrorCode = LsaNtStatusToWinError(res); | |||
if (winErrorCode != 0) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCenteredLine("LsaStorePrivateData failed: " + winErrorCode); | |||
} | |||
SafeNativeMethods.LSA_UNICODE_STRING ss = (SafeNativeMethods.LSA_UNICODE_STRING)Marshal.PtrToStructure(pData, typeof(SafeNativeMethods.LSA_UNICODE_STRING)); | |||
sout = Marshal.PtrToStringAuto(ss.Buffer); | |||
SafeNativeMethods.LsaClose(policyHandle); | |||
} | |||
SafeNativeMethods.FreeSid(sid); | |||
return sout; | |||
} | |||
#endregion | |||
private const string LogonKey = @"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"; | |||
public static bool Disable() => amecs.RunBasicAction("Disabling AutoLogon", "AutoLogon disabled successfully", new Action(() => | |||
{ | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DefaultUserName", Data = "", Type = Reg.RegistryValueType.REG_SZ}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "AutoAdminLogon", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "AutoLogonCount", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "ForceAutoLogon", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DisableCAD", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DefaultPassword", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
StoreData("DefaultPassword", ""); | |||
Thread.Sleep(1700); | |||
})); | |||
public static bool Enable() | |||
{ | |||
PrincipalContext context = new PrincipalContext(ContextType.Machine); | |||
string password = ""; | |||
while (true) | |||
{ | |||
password = new InputPrompt() { MaskInput = true, Text = "Enter your password, or press escape to quit: " }.Start(); | |||
if (password == null) | |||
return true; | |||
if (String.IsNullOrEmpty(password)) | |||
{ | |||
try | |||
{ | |||
Globals.User.ChangePassword("", ""); | |||
break; | |||
} catch {} | |||
} | |||
else if (context.ValidateCredentials(Globals.Username, password)) | |||
break; | |||
ConsoleTUI.OpenFrame.WriteLine("Incorrect password."); | |||
Console.WriteLine(); | |||
} | |||
try | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nEnabling AutoLogon"); | |||
using (new ConsoleUtils.LoadingIndicator(true)) | |||
{ | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DefaultUserName", Data = Globals.Username, Type = Reg.RegistryValueType.REG_SZ}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DefaultDomainName", Data = Environment.MachineName, Type = Reg.RegistryValueType.REG_SZ}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "AutoAdminLogon", Data = 1, Type = Reg.RegistryValueType.REG_DWORD}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "AutoLogonCount", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DisableCAD", Data = 1, Type = Reg.RegistryValueType.REG_DWORD}.Apply(); | |||
new Reg.Value() { KeyName = LogonKey, ValueName = "DefaultPassword", Operation = Reg.RegistryValueOperation.Delete}.Apply(); | |||
StoreData("DefaultPassword", password); | |||
Thread.Sleep(1700); | |||
} | |||
} catch (Exception e) | |||
{ | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("Error: " + e.Message.TrimEnd('\n').TrimEnd('\r'), ConsoleColor.Red, Console.BackgroundColor, new ChoicePrompt() | |||
{ | |||
AnyKey = true, | |||
Text = "Press any key to return to the Menu: " | |||
}); | |||
return false; | |||
} | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close($"AutoLogon enabled successfully", ConsoleColor.Green, Console.BackgroundColor, new ChoicePrompt() | |||
{ | |||
AnyKey = true, | |||
Text = "Press any key to return to the Menu: " | |||
}); | |||
return true; | |||
} | |||
} | |||
} |
@ -0,0 +1,239 @@ | |||
using System; | |||
using System.Diagnostics; | |||
using System.IO; | |||
using System.Security.Principal; | |||
using System.Threading; | |||
using amecs.Misc; | |||
using Ameliorated.ConsoleUtils; | |||
using Microsoft.Win32; | |||
namespace amecs.Actions | |||
{ | |||
public class Deameliorate | |||
{ | |||
private static string _mountedPath; | |||
private static string _winVer; | |||
private static string _win11Setup = ""; | |||
private static bool _win11 = Environment.OSVersion.Version.Build >= 22000; | |||
private const string ExplorerPatcherId = "D17F1E1A-5919-4427-8F89-A1A8503CA3EB"; | |||
public static bool DeAme() | |||
{ | |||
if (new ChoicePrompt() | |||
{ | |||
Text = @" | |||
This will de-ameliorate by reinstalling Windows. | |||
Although user data should be kept, we strongly recommend | |||
making backups of any important user data. | |||
Continue? (Y/N): " | |||
}.Start().Value == 1) return true; | |||
Program.Frame.Clear(); | |||
(_mountedPath, _, _winVer, _, _) = SelectWindowsImage.GetMediaPath(); | |||
if (_mountedPath == null) return false; | |||
if (new ChoicePrompt {Text = $"\r\nYour Windows image is {_winVer}. Continue? (Y/N): "}.Start().Value == 1) | |||
return true; | |||
var fc = Console.ForegroundColor; | |||
Console.ForegroundColor = ConsoleColor.Yellow; | |||
string userSid = null; | |||
try | |||
{ | |||
NSudo.GetSystemPrivilege(); | |||
NSudo.RunAsUser(() => | |||
{ | |||
userSid = WindowsIdentity.GetCurrent().User.ToString(); | |||
}); | |||
} | |||
catch | |||
{ | |||
// do nothing | |||
} | |||
try | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nUninstalling AME-installed UI software..."); | |||
string openShellId = null; | |||
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); | |||
foreach (var item in key.GetSubKeyNames()) | |||
{ | |||
try | |||
{ | |||
if (((string)key.OpenSubKey(item).GetValue("DisplayName")).Equals("Open-Shell")) | |||
openShellId = item; | |||
} | |||
catch | |||
{ | |||
// do nothing | |||
} | |||
} | |||
if (openShellId != null) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nUninstalling Open-Shell..."); | |||
Process.Start("MsiExec.exe", $"/X{openShellId} /quiet")?.WaitForExit(); | |||
if (userSid != null) | |||
{ | |||
var appData = (string)Registry.Users.OpenSubKey(userSid + @"\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders").GetValue("AppData"); | |||
if (Directory.Exists(Path.Combine(appData, "OpenShell"))) | |||
Directory.Delete(Path.Combine(appData, "OpenShell"), true); | |||
} | |||
} | |||
var epSetupPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ExplorerPatcher\ep_setup.exe"; | |||
if (File.Exists(epSetupPath)) | |||
{ | |||
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(); | |||
} catch (Exception e) | |||
{ | |||
ConsoleTUI.OpenFrame.Close( | |||
"Error when uninstalling software: " + e.Message, | |||
ConsoleColor.Red, Console.BackgroundColor, | |||
new ChoicePrompt { AnyKey = true, Text = "Press any key to continue anyways: " }); | |||
Program.Frame.Clear(); | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nContinuing without uninstalling software...\r\n"); | |||
} | |||
// 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" | |||
}) | |||
{ | |||
var hive = RegistryHive.LocalMachine; | |||
if (keyPath.StartsWith("HKU")) | |||
hive = RegistryHive.Users; | |||
var baseKey = RegistryKey.OpenBaseKey(hive, RegistryView.Default); | |||
var subKeyPath = keyPath.Substring(keyPath.IndexOf('\\') + 1); | |||
var key = baseKey.OpenSubKey(subKeyPath, true); | |||
if (key == null) continue; | |||
try | |||
{ | |||
baseKey.DeleteSubKeyTree(subKeyPath); | |||
} | |||
catch | |||
{ | |||
// do nothing - some values might fail, but almost all are deleted | |||
} | |||
key.Close(); | |||
} | |||
Thread.Sleep(3000); | |||
Program.Frame.Clear(); | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nCompleted initial setup!", ConsoleColor.Green); | |||
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(10000); | |||
Console.WriteLine(); | |||
try | |||
{ | |||
if (_win11) _win11Setup = "/Product Server"; | |||
Process.Start(Path.Combine(_mountedPath, "setup.exe"), $"/Auto Upgrade /DynamicUpdate Disable {_win11Setup}"); | |||
} catch (Exception e) | |||
{ | |||
ConsoleTUI.OpenFrame.Close( | |||
$"There was an error when trying to run the Windows Setup: {e}\r\nTry running the Windows Setup manually from File Explorer.", | |||
ConsoleColor.Red, Console.BackgroundColor, | |||
new ChoicePrompt { AnyKey = true, Text = $"Press any key to exit: " }); | |||
return false; | |||
} | |||
ConsoleTUI.OpenFrame.Close( | |||
"Completed, Windows Setup should have started.", | |||
ConsoleColor.Cyan, Console.BackgroundColor, | |||
new ChoicePrompt { AnyKey = true, Text = $"Press any key to go back: " }); | |||
return true; | |||
} | |||
} | |||
} |
@ -0,0 +1,21 @@ | |||
using System; | |||
using System.Threading; | |||
namespace amecs.Actions | |||
{ | |||
public class Elevation | |||
{ | |||
public static bool Elevate() => amecs.RunBasicAction("Elevating user to Administrator", "The current user is now an Administrator", new Action(() => | |||
{ | |||
Globals.Administrators.Members.Add(Globals.User); | |||
Globals.Administrators.Save(); | |||
Thread.Sleep(1000); | |||
}), true); | |||
public static bool DeElevate() => amecs.RunBasicAction("Revoking Admin rights from the current user", "Admin rights have been revoked for the current user", new Action(() => | |||
{ | |||
Globals.Administrators.Members.Remove(Globals.User); | |||
Globals.Administrators.Save(); | |||
Thread.Sleep(1000); | |||
}), true); | |||
} | |||
} |
@ -0,0 +1,113 @@ | |||
using System; | |||
using System.Diagnostics; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Security; | |||
using System.Threading; | |||
using Ameliorated.ConsoleUtils; | |||
using Microsoft.Win32; | |||
using System.Windows.Forms; | |||
namespace amecs.Actions | |||
{ | |||
public class Lockscreen | |||
{ | |||
public static bool ChangeImage() | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCenteredLine("Select an image"); | |||
Thread.Sleep(1000); | |||
var dialog = new System.Windows.Forms.OpenFileDialog(); | |||
dialog.Filter = "Image Files (*.jpg; *.jpeg; *.png; *.bmp; *.jfif)| *.jpg; *.jpeg; *.png; *.bmp; *.jfif"; // Filter files by extension | |||
dialog.Multiselect = false; | |||
dialog.InitialDirectory = Globals.UserFolder; | |||
NativeWindow window = new NativeWindow(); | |||
window.AssignHandle(Process.GetCurrentProcess().MainWindowHandle); | |||
if (dialog.ShowDialog(window) == DialogResult.OK) | |||
{ | |||
string file; | |||
try | |||
{ | |||
file = dialog.FileName; | |||
} | |||
catch (SecurityException e) | |||
{ | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("Security error: " + e.Message, ConsoleColor.Red, Console.BackgroundColor, new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "}); | |||
return false; | |||
} | |||
Console.WriteLine(); | |||
var choice = new ChoicePrompt() { Text = "Remove lockscreen blur? (Y/N): " }.Start(); | |||
if (!choice.HasValue) return true; | |||
bool blur = choice == 0; | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nSetting lockscreen image"); | |||
using (new ConsoleUtils.LoadingIndicator(true)) | |||
{ | |||
Thread.Sleep(500); | |||
try | |||
{ | |||
if (blur) | |||
new Reg.Value() | |||
{ | |||
KeyName = @"HKLM\SOFTWARE\Policies\Microsoft\Windows\System", | |||
ValueName = "DisableAcrylicBackgroundOnLogon", | |||
Type = Reg.RegistryValueType.REG_DWORD, | |||
Data = 1, | |||
}.Apply(); | |||
else | |||
new Reg.Value() | |||
{ | |||
KeyName = @"HKLM\SOFTWARE\Policies\Microsoft\Windows\System", | |||
ValueName = "DisableAcrylicBackgroundOnLogon", | |||
Type = Reg.RegistryValueType.REG_DWORD, | |||
Data = 0, | |||
}.Apply(); | |||
} catch { } | |||
new Reg.Value() | |||
{ | |||
KeyName = @"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Creative\" + Globals.UserSID, | |||
ValueName = "RotatingLockScreenEnabled", | |||
Type = Reg.RegistryValueType.REG_DWORD, | |||
Data = 0, | |||
}.Apply(); | |||
new Reg.Value() | |||
{ | |||
KeyName = @$"HKU\{Globals.UserSID}\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager", | |||
ValueName = "RotatingLockScreenEnabled", | |||
Type = Reg.RegistryValueType.REG_DWORD, | |||
Data = 0, | |||
}.Apply(); | |||
File.Delete(Environment.ExpandEnvironmentVariables(@"%WINDIR%\Web\Screen\img100.jpg")); | |||
File.Copy(file, Environment.ExpandEnvironmentVariables(@"%WINDIR%\Web\Screen\img100.jpg")); | |||
foreach (var dataDir in Directory.EnumerateDirectories(Environment.ExpandEnvironmentVariables(@"%PROGRAMDATA%\Microsoft\Windows\SystemData"))) | |||
{ | |||
var subDir = Path.Combine(dataDir, "ReadOnly"); | |||
if (!Directory.Exists(subDir)) | |||
continue; | |||
Directory.GetDirectories(subDir, "Lockscreen_*").ToList().ForEach(x => Directory.Delete(x, true)); | |||
} | |||
} | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("Lockscreen image changed successfully", ConsoleColor.Green, Console.BackgroundColor, new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "}); | |||
return true; | |||
} | |||
else | |||
{ | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("You must select an image.", new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "}); | |||
return true; | |||
} | |||
} | |||
} | |||
} |
@ -0,0 +1,124 @@ | |||
using System; | |||
using System.Diagnostics; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Security; | |||
using System.Threading; | |||
using System.Windows.Forms; | |||
using Ameliorated.ConsoleUtils; | |||
using System.Drawing; | |||
using System.Security.AccessControl; | |||
using System.Security.Principal; | |||
namespace amecs.Actions | |||
{ | |||
public class Profile | |||
{ | |||
public static bool ChangeImage() | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCenteredLine("Select an image"); | |||
Thread.Sleep(1000); | |||
var dialog = new System.Windows.Forms.OpenFileDialog(); | |||
dialog.Filter = "Image Files (*.jpg; *.jpeg; *.png; *.bmp; *.jfif)| *.jpg; *.jpeg; *.png; *.bmp; *.jfif"; // Filter files by extension | |||
dialog.Multiselect = false; | |||
dialog.InitialDirectory = Globals.UserFolder; | |||
NativeWindow window = new NativeWindow(); | |||
window.AssignHandle(Process.GetCurrentProcess().MainWindowHandle); | |||
if (dialog.ShowDialog(window) == DialogResult.OK) | |||
{ | |||
string file; | |||
try | |||
{ | |||
file = dialog.FileName; | |||
} | |||
catch (SecurityException e) | |||
{ | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("Security error: " + e.Message, ConsoleColor.Red, Console.BackgroundColor, new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "}); | |||
return false; | |||
} | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nSetting profile image"); | |||
using (new ConsoleUtils.LoadingIndicator(true)) | |||
{ | |||
var pfpDir = Path.Combine(Environment.ExpandEnvironmentVariables("%PUBLIC%\\AccountPictures"), Globals.UserSID); | |||
if (Directory.Exists(pfpDir)) | |||
{ | |||
try | |||
{ | |||
Directory.Delete(pfpDir, true); | |||
} catch (Exception e) | |||
{ | |||
var logdi = new DirectoryInfo(pfpDir) { Attributes = FileAttributes.Normal }; | |||
try | |||
{ | |||
NSudo.GetOwnershipPrivilege(); | |||
var logdirsec = logdi.GetAccessControl(); | |||
logdirsec.SetOwner(WindowsIdentity.GetCurrent().User); | |||
logdi.SetAccessControl(logdirsec); | |||
logdirsec = new DirectorySecurity(); | |||
logdirsec.AddAccessRule(new FileSystemAccessRule(WindowsIdentity.GetCurrent().User, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)); |