Skip to content

Commit 4a11404

Browse files
Update RemoveVMwUI2.ps1
1 parent 84e3947 commit 4a11404

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Tools/RemoveVMwUI2/RemoveVMwUI2.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33
Untitled
44
#>
55

6+
# Get the ID and security principal of the current user account
7+
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
8+
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
9+
10+
# Get the security principal for the Administrator role
11+
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
12+
13+
# Check to see if we are currently running "as Administrator"
14+
if ($myWindowsPrincipal.IsInRole($adminRole))
15+
{
16+
# We are running "as Administrator" - so change the title and background color to indicate this
17+
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
18+
$Host.UI.RawUI.BackgroundColor = "DarkBlue"
19+
clear-host
20+
}
21+
else
22+
{
23+
# We are not running "as Administrator" - so relaunch as administrator
24+
25+
# Create a new process object that starts PowerShell
26+
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
27+
28+
# Specify the current script path and name as a parameter
29+
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
30+
31+
# Indicate that the process should be elevated
32+
$newProcess.Verb = "runas";
33+
34+
# Start the new process
35+
[System.Diagnostics.Process]::Start($newProcess);
36+
37+
# Exit from the current, unelevated, process
38+
exit
39+
}
40+
641
$DLL = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
742
Add-Type -MemberDefinition $DLL -name NativeMethods -namespace Win32
843
$Process = (Get-Process PowerShell | Where-Object MainWindowTitle -like '*RemoveVMwUI*').MainWindowHandle

0 commit comments

Comments
 (0)