Install-MakeMeAdmin.ps1
Make Me Admin is a simple, open-source application for Windows that allows standard user accounts to be elevated to administrator-level, on a temporary basis.
What?
PowerShell script that performs an automated, silent, installation of 'MakeMeAdmin' then performs customization via Registry Keys.
Why?
This was created by u/SimplifyMSP in response to a post submitted by u/Unkn0wn-G0d in r/PowerShell titled, "Script for creating / modifying key in reg-editor?"
Resources and References
- Microsoft Docs
- Win32_PRODUCT Issues
- MakeMeAdmin
Install-MakeMeAdmin.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | <#
- [Name] Install-MakeMeAdmin.ps1
- [Description] Downloads and installs MakeMeAdmin v2.3.0 (64-Bit) then configures behavior settings, or policies, via Registry keys.
- [Version] 1.02.27.3
- [Resources and References]
- Official Documentation | Registry Settings
- https://github.com/pseymour/MakeMeAdmin/wiki/Registry-Settings
- [Changelog]
- [Feb 27, 2023] 1.02.27.3
- [FIXED] Resolved an issue with the Registry Key paths used to manage settings for "Make Me Admin"
- [FIXED] Resolved an issue causing args to not be properly passed through to the Invoke-Executable function.
- [FIXED] Script now properly breaks and exits if the installation of the .MSI returns anything other than "Exit Code: 0"
- [Feb 27, 2023] 1.02.27.1
- [NEW] Added transcript (automatic logging) functionality
- [NEW] Now tracks the Exit Code passed through from msiexec after installing MakeMeAdmin, stores it as an internal/private variable, then exits this script with that same Exit Code.
- [NEW] Added "behavior" variables for ProgressPreference and ErrorActionPreference.
- [NEW] Added an internal/private function (Invoke-Executable) to properly, and extensively, handle starting a process from PowerShell.
- [UPDATED] Replaced "App Detection" functionality (previously checked Win32_PRODUCT via WMI Query) to now check for the full file path to the Windows Service executable (.exe)
- [UPDATED] Refactored code related to creating Registry Keys to use variables for the Registry Key paths rather than repeating inline strings
- [UPDATED] Changed behavior of MakeMeAdmin installation to have msiexec call the direct download URL for the .MSI file (as opposed to the previous behavior which required downloading the .MSI to a local folder on the PC first.)
#>
Start-Transcript -OutputDirectory "C:\Users\Public" -Append -Force
Clear-Host
Write-Host "[ Install-MakeMeAdmin.ps1 ]"
Write-Host "Version: 1.02.27.3"
Write-Host
# Define Behaviors
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
# Define Variables
$APP_DOWNLOAD_URL = "https://github.com/pseymour/MakeMeAdmin/raw/v2.3-fr/Installers/en-us/MakeMeAdmin%202.3.0%20x64.msi"
$APP_DETECTION_PATH = "C:\Program Files\Make Me Admin\MakeMeAdminService.exe"
$APP_EXIT_CODE = ""
$REG_SETTINGS_ROOT = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Sinclair Community College\Make Me Admin"
$REG_POLICIES_ROOT = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Sinclair Community College\Make Me Admin"
# Define Functions
## [ValidateNotNullOrEmpty()]
function Invoke-Executable {
param(
[parameter(Mandatory = $true, HelpMessage = "Specify the file name or path of the executable to be invoked, including the extension.")]
[string]$FilePath,
[parameter(Mandatory = $false, HelpMessage = "Specify arguments that will be passed to the executable.")]
[string]$Arguments
)
try {
# Create the Process Info object which contains details about the process
$ProcessStartInfoObject = New-object System.Diagnostics.ProcessStartInfo
$ProcessStartInfoObject.FileName = $FilePath
$ProcessStartInfoObject.CreateNoWindow = $true
$ProcessStartInfoObject.UseShellExecute = $false
$ProcessStartInfoObject.RedirectStandardOutput = $true
$ProcessStartInfoObject.RedirectStandardError = $true
$ProcessStartInfoObject.Arguments = $Arguments
# Create the object that will represent the process
$Process = New-Object -TypeName "System.Diagnostics.Process"
$Process.StartInfo = $ProcessStartInfoObject
# Start process
[void]$Process.Start()
# Wait for the process to exit
$Process.WaitForExit()
# Return an object that contains the exit code
$ProcExitCode = $Process.ExitCode
#Write-Host "[Invoke-Executable] Exit Code: $ProcExitCode"
return $ProcExitCode
}
catch [System.Exception] {
Write-Host "$($MyInvocation.MyCommand): Error message: $($_.Exception.Message)"
return "1"
}
}
# Initialize (launch main part of) script
Write-Host "Determining whether MakeMeAdmin is already installed, please wait..."
# If the MakeMeAdmin service executable isn't found, the app needs to be downloaded and installed.
if (!(Test-Path $APP_DETECTION_PATH)) {
Write-Host "MakeMeAdmin installation not detected!"
Write-Host "Installing MakeMeAdmin, please wait..."
Set-Location -Path "C:\Windows\System32"
$Custom_Args = "/i ""$APP_DOWNLOAD_URL"" /qn"
$APP_EXIT_CODE = Invoke-Executable -FilePath "msiexec" -Arguments $Custom_Args
if ($APP_EXIT_CODE.ToString() -ne "0") {
Write-Host "Installation failed. Please check the logs and try again."
Exit 1
}
Write-Host "Installation complete!"
}
else {
Write-Host "MakeMeAdmin is already installed!"
}
# Create the MakeMeAdmin key and set the AdminRightTimeout value to 60 minutes
Write-Host "Configuring MakeMeAdmin behavior settings via Registry, please wait..."
if (!(Test-Path -Path $REG_SETTINGS_ROOT)) {
New-Item -Path $REG_SETTINGS_ROOT -Force | Out-Null
Write-Host "[CREATED] $REG_SETTINGS_ROOT"
}
else {
Write-Host "$REG_SETTINGS_ROOT already exists!"
}
New-ItemProperty -Path $REG_SETTINGS_ROOT -Name "MakeMeAdmin" -Value "" -Force | Out-Null
Write-Host "[CREATED] $REG_SETTINGS_ROOT\MakeMeAdmin"
New-ItemProperty -Path $REG_SETTINGS_ROOT -Name "AdminRightsTimeout" -Value "60" -PropertyType DWORD -Force | Out-Null
Write-Host "[CREATED] $REG_SETTINGS_ROOT\AdminRightsTimeout"
Write-Host "Successfully set value of 'AdminRightsTimeout' to 60 (minutes.)"
Write-Host "Custom configuration successfully applied!"
# End
Write-Host "Operation completed successfully!"
Stop-Transcript
Exit $APP_EXIT_CODE
|
Additional Resources
- Obtain a List of Installed Applications and their Uninstallation Keys from Registry