Author | SHA1 | Message | Date |
---|---|---|---|
|
e986cde90b
|
fix(.net 3.5): final touches (ejecting ISO, etc) | 2 weeks ago |
|
96135bca0d
|
fix(.net 3.5): general fixes | 2 weeks ago |
|
e0d0bfd030
|
feat: .NET 3.5 with USB/folder | 2 weeks ago |
|
8c6c9c3d3c
|
feat(users): password reconfirmation | 4 weeks ago |
|
d1858244ba | Update README | 4 months ago |
|
14359b9855 | C# Update | 4 months ago |
|
8fb460ba4f | Update 'README.md' | 9 months ago |
|
bc8cec4dab | Update 'README.md' | 9 months ago |
|
8b04e77b8f | Update 'README.md' | 9 months ago |
|
d5778d8e47 | Update 'README.md' | 9 months ago |
|
8688290afd | Update README | 11 months ago |
|
6ed9ff89f6 | Update README | 11 months ago |
|
09cece9a2b |
Release v1.4
Fix server link fetch failing due to a new git link Fix lockscreen blur toggle issue Fix hibernation detection |
11 months ago |
|
1d8824361f | Remove Usage note from README | 1 year ago |
|
fe6a69b0b9 |
Release v1.3
Reupload through gitea GUI because gitea likes to encode when downloading from GUI it wrong otherwise |
1 year ago |
|
261ffbfe3b |
Release v1.3
Changelog: Fix WSL "Not Supported" string breaking the Extra menu on systems with updated WSL versions Override DISM language to English to avoid issues with FINDSTR on systems with non-English system languages Fix Bulgarian keyboard layout codes Fix line spacing on some lines |
1 year ago |
|
132207db69 |
Update README
Move the note regarding Download Repository > ZIP to the top of the Usage section |
1 year ago |
|
c77ddc8b92 | Update README | 1 year ago |
|
e9826f2421 | Update README | 1 year ago |
|
7e25b9492e |
Update to v1.2
Add Enable/Disable Notification Center function Add Enable/Disable desktop notifications function Change tasklist filtering to hopefully work with different system languages Change some functions that ask to restart to instead ask to sign out Change wording from "needed" to "required" on some text Improve WSH function Add slight delay to image selection for lockscreen and profile image functions for a slightly improved user experience Revamp back-end menu system Various minor code improvements |
1 year ago |
|
8975759622 |
Update 'screenshot.png'
Update 'screenshot.png' |
1 year ago |
|
2d94f7cc70 |
Update to v1.1
Improve Extra menu loading time Improve UI Improve Beta User Creation function consistency Fix AutoLogon not working with usernames that include spaces Fix bugs and improve code |
1 year ago |
@ -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,221 @@ | |||
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 System.Windows.Forms; | |||
using Misc.FolderPicker; | |||
using Ameliorated.ConsoleUtils; | |||
using Microsoft.Dism; | |||
namespace amecs.Actions | |||
{ | |||
public class _NET | |||
{ | |||
private static string file; | |||
private static bool CheckFileViolation(string inputFile) | |||
{ | |||
try | |||
{ | |||
file = inputFile; | |||
} | |||
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 true; | |||
} | |||
return false; | |||
} | |||
private static bool DismountImage() | |||
{ | |||
ProcessStartInfo startInfo = new ProcessStartInfo(); | |||
startInfo.CreateNoWindow = false; | |||
startInfo.UseShellExecute = false; | |||
startInfo.FileName = "PowerShell.exe"; | |||
startInfo.WindowStyle = ProcessWindowStyle.Hidden; | |||
startInfo.Arguments = $"-NoP -C \"Dismount-DiskImage '{file}'\""; | |||
startInfo.RedirectStandardOutput = true; | |||
var proc = Process.Start(startInfo); | |||
proc.WaitForExit(); | |||
return true; | |||
} | |||
public static bool Install() | |||
{ | |||
string letter; | |||
var choice = new ChoicePrompt() { Text = "To install .NET 3.5, Windows installation media is needed.\r\nDo you have a Windows USB instead of an ISO? (Y/N): " }.Start(); | |||
if (choice == null) return false; | |||
var usingFolder = choice == 0; | |||
if (usingFolder) | |||
{ | |||
var dlg = new FolderPicker(); | |||
dlg.InputPath = Globals.UserFolder; | |||
if (!dlg.ShowDialog(IntPtr.Zero, false).GetValueOrDefault()) | |||
{ | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("\r\nYou must select a folder or drive.", new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "}); | |||
return true; | |||
} | |||
if (CheckFileViolation(dlg.ResultPath)) return false; | |||
letter = dlg.ResultPath; | |||
} | |||
else | |||
{ | |||
var dialog = new System.Windows.Forms.OpenFileDialog(); | |||
dialog.Filter = "ISO Files (*.ISO)| *.ISO"; // 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) | |||
{ | |||
if (CheckFileViolation(dialog.FileName)) return false; | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nMounting ISO"); | |||
} | |||
else | |||
{ | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("\r\nYou must select an ISO.", new ChoicePrompt() {AnyKey = true, Text = "Press any key to return to the Menu: "}); | |||
return true; | |||
} | |||
using (new ConsoleUtils.LoadingIndicator(true)) | |||
{ | |||
ProcessStartInfo startInfo = new ProcessStartInfo(); | |||
startInfo.CreateNoWindow = false; | |||
startInfo.UseShellExecute = false; | |||
startInfo.FileName = "PowerShell.exe"; | |||
startInfo.WindowStyle = ProcessWindowStyle.Hidden; | |||
startInfo.Arguments = | |||
$"-NoP -C \"(Mount-DiskImage '{file}' -PassThru | Get-Volume).DriveLetter + ':\'\""; | |||
startInfo.RedirectStandardOutput = true; | |||
var proc = Process.Start(startInfo); | |||
proc.WaitForExit(); | |||
letter = proc.StandardOutput.ReadLine(); | |||
} | |||
} | |||
if (!Directory.Exists(letter + @"\sources\sxs") || !Directory.GetFiles(letter + @"\sources\sxs", "*netfx3*").Any()) | |||
{ | |||
DismountImage(); | |||
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(); | |||
bool inProgress = false; | |||
try | |||
{ | |||
using (var indicator = new ConsoleUtils.LoadingIndicator()) | |||
{ | |||
DismApi.Initialize(DismLogLevel.LogErrors); | |||
using (var session = DismApi.OpenOnlineSession()) | |||
{ | |||
var stdout = GetStdHandle(-11); | |||
bool indicatorStopped = false; | |||
var maxHashTags = (ConsoleTUI.OpenFrame.DisplayWidth - 5); | |||
DismApi.EnableFeatureByPackagePath(session, "NetFX3", null, true, true, new List<string>() { letter + @"\sources\sxs" }, delegate(DismProgress progress) | |||
{ | |||
inProgress = true; | |||
if (!indicatorStopped) | |||
{ | |||
indicator.Stop(); | |||
Console.SetCursorPosition(leftCache, topCache); | |||
Console.WriteLine(" "); | |||
} | |||
indicatorStopped = true; | |||
var progressPerc = progress.Current / 10; | |||
var currentHashTags = (int)Math.Ceiling(Math.Min(((double)progressPerc / 100) * maxHashTags, maxHashTags)); | |||
var spaces = maxHashTags - currentHashTags + (4 - progressPerc.ToString().Length); | |||
var sb = new StringBuilder(new string('#', currentHashTags) + new string(' ', spaces) + progressPerc + "%"); | |||
uint throwaway; | |||
WriteConsoleOutputCharacter(stdout, sb, (uint)sb.Length, new Languages.COORD((short)ConsoleTUI.OpenFrame.DisplayOffset, (short)Console.CursorTop), out throwaway); | |||
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(); | |||
if (!usingFolder) DismountImage(); | |||
} | |||
} catch (Exception e) | |||
{ | |||
while (inProgress) | |||
{ | |||
Thread.Sleep(50); | |||
} | |||
if (!usingFolder) | |||
{ | |||
try | |||
{ | |||
DismountImage(); | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
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(); | |||
if (!usingFolder) | |||
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,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)); | |||
logdi.SetAccessControl(logdirsec); | |||
} catch (Exception exception) | |||
{ | |||
} | |||
foreach (var info in logdi.GetFileSystemInfos("*", SearchOption.AllDirectories)) | |||
{ | |||
info.Attributes = FileAttributes.Normal; | |||
} | |||
Directory.Delete(pfpDir, true); | |||
} | |||
} | |||
Directory.CreateDirectory(pfpDir); | |||
var image = Image.FromFile(file); | |||
var pfpKey = @"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\" + Globals.UserSID; | |||
new Reg.Key() { KeyName = pfpKey, Operation = RegistryOperation.Delete }.Apply(); | |||
foreach (var res in new [] { 32, 40, 48, 64, 96, 192, 208, 240, 424, 448, 1080 }) | |||
{ | |||
var bitmap = new Bitmap(res, res); | |||
var graph = Graphics.FromImage(bitmap); | |||
graph.DrawImage(image, 0, 0, res, res); | |||
var saveLoc = Path.Combine(pfpDir, $"{res}x{res}.png"); | |||
bitmap.Save(saveLoc); | |||
new Reg.Value() { KeyName = pfpKey, ValueName = "Image" + res, Type = Reg.RegistryValueType.REG_SZ, Data = saveLoc }.Apply(); | |||
} | |||
new Reg.Value() { KeyName = pfpKey, ValueName = "UserPicturePath", Type = Reg.RegistryValueType.REG_SZ, Data = Path.Combine(pfpDir, $"448x448.png") }.Apply(); | |||
try | |||
{ | |||
Process proc = new Process(); | |||
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | |||
proc.StartInfo.FileName = "gpupdate.exe"; | |||
proc.StartInfo.Arguments = "/force"; | |||
proc.Start(); | |||
proc.WaitForExit(20000); | |||
} catch { } | |||
} | |||
Console.WriteLine(); | |||
ConsoleTUI.OpenFrame.Close("Profile 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,220 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.DirectoryServices; | |||
using System.DirectoryServices.AccountManagement; | |||
using Ameliorated.ConsoleUtils; | |||
using System.Linq; | |||
using System.Security; | |||
using System.Text.RegularExpressions; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
namespace amecs.Actions | |||
{ | |||
public static class UserPass | |||
{ | |||
public static bool ShowMenu() | |||
{ | |||
var mainMenu = new Ameliorated.ConsoleUtils.Menu() | |||
{ | |||
Choices = | |||
{ | |||
new Menu.MenuItem("Change Username", new Func<bool>(ChangeUsername)), | |||
new Menu.MenuItem("Change Password", new Func<bool>(ChangePassword)), | |||
new Menu.MenuItem("Change Display Name", new Func<bool>(ChangeDisplayName)), | |||
new Menu.MenuItem("Change Administrator Password", new Func<bool>(ChangeAdminPassword)), | |||
Menu.MenuItem.Blank, | |||
new Menu.MenuItem("Return to Menu", new Func<bool>(() => true)), | |||
new Menu.MenuItem("Exit", new Func<bool>(Globals.Exit)), | |||
}, | |||
SelectionForeground = ConsoleColor.Green | |||
}; | |||
mainMenu.Write(); | |||
var result = (Func<bool>)mainMenu.Load(); | |||
return result.Invoke(); | |||
} | |||
public static bool ChangeUsername() | |||
{ | |||
try | |||
{ | |||
while (true) | |||
{ | |||
var username = new InputPrompt() { Text = "Enter new username, or press escape to quit: " }.Start(); | |||
if (username == null) | |||
return true; | |||
if (String.IsNullOrEmpty(username) || !Regex.Match(username, @"^\w[\w\.\- ]{0,19}$").Success) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteLine("Username is invalid."); | |||
Console.WriteLine(); | |||
continue; | |||
} | |||
if (Globals.Username.Equals(username)) | |||
{ | |||
ConsoleTUI.OpenFrame.WriteLine("Username matches the current username."); | |||
Console.WriteLine(); | |||
continue; | |||
} | |||
try | |||
{ | |||
ConsoleTUI.OpenFrame.WriteCentered("\r\nSetting new username"); | |||
using (new ConsoleUtils.LoadingIndicator(true)) | |||
{ | |||
DirectoryEntry entry = (DirectoryEntry)Globals.User.GetUnderlyingObject(); | |||
entry.Rename(username); | |||
entry.CommitChanges(); | |||
PrincipalContext context = new PrincipalContext(ContextType.Machine); | |||
PrincipalSearcher userPrincipalSearcher = new PrincipalSearcher(new UserPrincipal(context)); | |||
Globals.User = userPrincipalSearcher.FindAll().FirstOrDefault(x => (x is UserPrincipal) && x.Sid.Value == Globals.UserSID) as UserPrincipal; | |||
break; | |||
} | |||
} catch (System.Runtime.InteropServices.COMException e) | |||
{ | |||
if (e.ErrorCode != -2147022694) | |||
throw e; | |||
ConsoleTUI.OpenFrame.WriteLine("Username is invalid."); | |||
Console.WriteLine(); | |||
} | |||
} | |||