Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #109
- Loading branch information
Showing
7 changed files
with
390 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
* text=auto | ||
*.bat text eol=crlf | ||
*.ps1 text eol=crlf | ||
*.psm1 text eol=crlf | ||
*.reg text eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,106 @@ | ||
function Takeown-Registry($key) { | ||
# TODO does not work for all root keys yet | ||
switch ($key.split('\')[0]) { | ||
"HKEY_CLASSES_ROOT" { | ||
$reg = [Microsoft.Win32.Registry]::ClassesRoot | ||
$key = $key.substring(18) | ||
} | ||
"HKEY_CURRENT_USER" { | ||
$reg = [Microsoft.Win32.Registry]::CurrentUser | ||
$key = $key.substring(18) | ||
} | ||
"HKEY_LOCAL_MACHINE" { | ||
$reg = [Microsoft.Win32.Registry]::LocalMachine | ||
$key = $key.substring(19) | ||
} | ||
} | ||
|
||
# get administraor group | ||
$admins = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") | ||
$admins = $admins.Translate([System.Security.Principal.NTAccount]) | ||
|
||
# set owner | ||
$key = $reg.OpenSubKey($key, "ReadWriteSubTree", "TakeOwnership") | ||
$acl = $key.GetAccessControl() | ||
$acl.SetOwner($admins) | ||
$key.SetAccessControl($acl) | ||
|
||
# set FullControl | ||
$acl = $key.GetAccessControl() | ||
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($admins, "FullControl", "Allow") | ||
$acl.SetAccessRule($rule) | ||
$key.SetAccessControl($acl) | ||
} | ||
|
||
function Takeown-File($path) { | ||
takeown.exe /A /F $path | ||
$acl = Get-Acl $path | ||
|
||
# get administraor group | ||
$admins = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") | ||
$admins = $admins.Translate([System.Security.Principal.NTAccount]) | ||
|
||
# add NT Authority\SYSTEM | ||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($admins, "FullControl", "None", "None", "Allow") | ||
$acl.AddAccessRule($rule) | ||
|
||
Set-Acl -Path $path -AclObject $acl | ||
} | ||
|
||
function Takeown-Folder($path) { | ||
Takeown-File $path | ||
foreach ($item in Get-ChildItem $path) { | ||
if (Test-Path $item -PathType Container) { | ||
Takeown-Folder $item.FullName | ||
} else { | ||
Takeown-File $item.FullName | ||
} | ||
} | ||
} | ||
|
||
function Elevate-Privileges { | ||
param($Privilege) | ||
$Definition = @" | ||
using System; | ||
using System.Runtime.InteropServices; | ||
public class AdjPriv { | ||
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)] | ||
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr rele); | ||
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)] | ||
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok); | ||
[DllImport("advapi32.dll", SetLastError = true)] | ||
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid); | ||
[StructLayout(LayoutKind.Sequential, Pack = 1)] | ||
internal struct TokPriv1Luid { | ||
public int Count; | ||
public long Luid; | ||
public int Attr; | ||
} | ||
internal const int SE_PRIVILEGE_ENABLED = 0x00000002; | ||
internal const int TOKEN_QUERY = 0x00000008; | ||
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; | ||
public static bool EnablePrivilege(long processHandle, string privilege) { | ||
bool retVal; | ||
TokPriv1Luid tp; | ||
IntPtr hproc = new IntPtr(processHandle); | ||
IntPtr htok = IntPtr.Zero; | ||
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); | ||
tp.Count = 1; | ||
tp.Luid = 0; | ||
tp.Attr = SE_PRIVILEGE_ENABLED; | ||
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid); | ||
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); | ||
return retVal; | ||
} | ||
} | ||
"@ | ||
$ProcessHandle = (Get-Process -id $pid).Handle | ||
$type = Add-Type $definition -PassThru | ||
$type[0]::EnablePrivilege($processHandle, $Privilege) | ||
} | ||
function Takeown-Registry($key) { | ||
# TODO does not work for all root keys yet | ||
switch ($key.split('\')[0]) { | ||
"HKEY_CLASSES_ROOT" { | ||
$reg = [Microsoft.Win32.Registry]::ClassesRoot | ||
$key = $key.substring(18) | ||
} | ||
"HKEY_CURRENT_USER" { | ||
$reg = [Microsoft.Win32.Registry]::CurrentUser | ||
$key = $key.substring(18) | ||
} | ||
"HKEY_LOCAL_MACHINE" { | ||
$reg = [Microsoft.Win32.Registry]::LocalMachine | ||
$key = $key.substring(19) | ||
} | ||
} | ||
|
||
# get administraor group | ||
$admins = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") | ||
$admins = $admins.Translate([System.Security.Principal.NTAccount]) | ||
|
||
# set owner | ||
$key = $reg.OpenSubKey($key, "ReadWriteSubTree", "TakeOwnership") | ||
$acl = $key.GetAccessControl() | ||
$acl.SetOwner($admins) | ||
$key.SetAccessControl($acl) | ||
|
||
# set FullControl | ||
$acl = $key.GetAccessControl() | ||
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($admins, "FullControl", "Allow") | ||
$acl.SetAccessRule($rule) | ||
$key.SetAccessControl($acl) | ||
} | ||
|
||
function Takeown-File($path) { | ||
takeown.exe /A /F $path | ||
$acl = Get-Acl $path | ||
|
||
# get administraor group | ||
$admins = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") | ||
$admins = $admins.Translate([System.Security.Principal.NTAccount]) | ||
|
||
# add NT Authority\SYSTEM | ||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($admins, "FullControl", "None", "None", "Allow") | ||
$acl.AddAccessRule($rule) | ||
|
||
Set-Acl -Path $path -AclObject $acl | ||
} | ||
|
||
function Takeown-Folder($path) { | ||
Takeown-File $path | ||
foreach ($item in Get-ChildItem $path) { | ||
if (Test-Path $item -PathType Container) { | ||
Takeown-Folder $item.FullName | ||
} else { | ||
Takeown-File $item.FullName | ||
} | ||
} | ||
} | ||
|
||
function Elevate-Privileges { | ||
param($Privilege) | ||
$Definition = @" | ||
using System; | ||
using System.Runtime.InteropServices; | ||
public class AdjPriv { | ||
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)] | ||
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr rele); | ||
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)] | ||
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok); | ||
[DllImport("advapi32.dll", SetLastError = true)] | ||
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid); | ||
[StructLayout(LayoutKind.Sequential, Pack = 1)] | ||
internal struct TokPriv1Luid { | ||
public int Count; | ||
public long Luid; | ||
public int Attr; | ||
} | ||
internal const int SE_PRIVILEGE_ENABLED = 0x00000002; | ||
internal const int TOKEN_QUERY = 0x00000008; | ||
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; | ||
public static bool EnablePrivilege(long processHandle, string privilege) { | ||
bool retVal; | ||
TokPriv1Luid tp; | ||
IntPtr hproc = new IntPtr(processHandle); | ||
IntPtr htok = IntPtr.Zero; | ||
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); | ||
tp.Count = 1; | ||
tp.Luid = 0; | ||
tp.Attr = SE_PRIVILEGE_ENABLED; | ||
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid); | ||
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); | ||
return retVal; | ||
} | ||
} | ||
"@ | ||
$ProcessHandle = (Get-Process -id $pid).Handle | ||
$type = Add-Type $definition -PassThru | ||
$type[0]::EnablePrivilege($processHandle, $Privilege) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
# Description: | ||
# This script remove strang looking stuff which will probably result in a break | ||
# of your system. It should not be used unless you want to test out a few | ||
# things. It is named `experimental_unfuckery.ps1` for a reason. | ||
|
||
Import-Module -DisableNameChecking $PSScriptRoot\..\lib\take-own.psm1 | ||
|
||
echo "Elevating priviledges for this process" | ||
do {} until (Elevate-Privileges SeTakeOwnershipPrivilege) | ||
|
||
echo "Force removing system apps" | ||
$needles = @( | ||
#"Anytime" | ||
"BioEnrollment" | ||
#"Browser" | ||
"ContactSupport" | ||
#"Cortana" # This will disable startmenu search. | ||
#"Defender" | ||
"Feedback" | ||
"Flash" | ||
"Gaming" | ||
#"InternetExplorer" | ||
#"Maps" | ||
"OneDrive" | ||
#"Wallet" | ||
#"Xbox" # This will result in a bootloop since upgrade 1511 | ||
) | ||
|
||
foreach ($needle in $needles) { | ||
echo "Trying to remove all packages containing $needle" | ||
|
||
$pkgs = (ls "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages" | | ||
where Name -Like "*$needle*") | ||
|
||
foreach ($pkg in $pkgs) { | ||
$pkgname = $pkg.Name.split('\')[-1] | ||
|
||
Takeown-Registry($pkg.Name) | ||
Takeown-Registry($pkg.Name + "\Owners") | ||
|
||
Set-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name Visibility -Value 1 | ||
New-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name DefVis -PropertyType DWord -Value 2 | ||
Remove-Item -Path ("HKLM:" + $pkg.Name.Substring(18) + "\Owners") | ||
|
||
dism.exe /Online /Remove-Package /PackageName:$pkgname /NoRestart | ||
} | ||
} | ||
# Description: | ||
# This script remove strang looking stuff which will probably result in a break | ||
# of your system. It should not be used unless you want to test out a few | ||
# things. It is named `experimental_unfuckery.ps1` for a reason. | ||
|
||
Import-Module -DisableNameChecking $PSScriptRoot\..\lib\take-own.psm1 | ||
|
||
echo "Elevating priviledges for this process" | ||
do {} until (Elevate-Privileges SeTakeOwnershipPrivilege) | ||
|
||
echo "Force removing system apps" | ||
$needles = @( | ||
#"Anytime" | ||
"BioEnrollment" | ||
#"Browser" | ||
"ContactSupport" | ||
#"Cortana" # This will disable startmenu search. | ||
#"Defender" | ||
"Feedback" | ||
"Flash" | ||
"Gaming" | ||
#"InternetExplorer" | ||
#"Maps" | ||
"OneDrive" | ||
#"Wallet" | ||
#"Xbox" # This will result in a bootloop since upgrade 1511 | ||
) | ||
|
||
foreach ($needle in $needles) { | ||
echo "Trying to remove all packages containing $needle" | ||
|
||
$pkgs = (ls "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages" | | ||
where Name -Like "*$needle*") | ||
|
||
foreach ($pkg in $pkgs) { | ||
$pkgname = $pkg.Name.split('\')[-1] | ||
|
||
Takeown-Registry($pkg.Name) | ||
Takeown-Registry($pkg.Name + "\Owners") | ||
|
||
Set-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name Visibility -Value 1 | ||
New-ItemProperty -Path ("HKLM:" + $pkg.Name.Substring(18)) -Name DefVis -PropertyType DWord -Value 2 | ||
Remove-Item -Path ("HKLM:" + $pkg.Name.Substring(18) + "\Owners") | ||
|
||
dism.exe /Online /Remove-Package /PackageName:$pkgname /NoRestart | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
@echo off | ||
|
||
shutdown /o /r /t 00 | ||
@echo off | ||
|
||
shutdown /o /r /t 00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Windows Registry Editor Version 5.00 | ||
|
||
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize] | ||
"AppsUseLightTheme"=dword:00000000 | ||
|
||
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize] | ||
"AppsUseLightTheme"=dword:00000000 | ||
Windows Registry Editor Version 5.00 | ||
|
||
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize] | ||
"AppsUseLightTheme"=dword:00000000 | ||
|
||
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize] | ||
"AppsUseLightTheme"=dword:00000000 |
Oops, something went wrong.
d3bf3e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[op[po[po[po