added admin rights check

This commit is contained in:
2021-11-14 11:52:32 -05:00
parent 5161eb74a4
commit dd95afd2a0

39
kms.ps1
View File

@@ -10,6 +10,45 @@
# Server (3)
#####################
# Get Admin Rights ##
####################
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator" and not 64 bit
if ($myWindowsPrincipal.IsInRole($adminRole) -and -not [environment]::Is64BitProcess) {
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
#$Host.UI.RawUI.BackgroundColor = "DarkBlue"
clear-host
} else {
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell x86
# Check to see if we are currently running x86 arch
# the LHO script can only run with 32 bit powershell
if (([environment]::Is64BitProcess)) {
# run the 32 bit powershell exe when on a 64 bit computer
$newProcess = new-object System.Diagnostics.ProcessStartInfo "C:\Windows\SysWoW64\WindowsPowerShell\v1.0\powershell.exe";
} else {
# run the normal 32 bit powershell exe when on 32 bit computer
$newProcess = new-object System.Diagnostics.ProcessStartInfo "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe";
}
# Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated, process
exit
}
# Windows OS
# Set KMS Host
c:\Windows\System32\cscript.exe /nologo c:\Windows\System32\slmgr.vbs /skms gauntkms.home.johnhgaunt.com