
Unascommand"-force-名称''-value'"c:windowssystem32windows "-noexit"%1" $null = $Host.UI.RawUI.ReadKey ( "NoEcho,IncludeKeyDown" ) Write-Host -NoNewLine "Press any key to continue."

# Run your code that needs to be elevated here. # Exit from the current, unelevated, process # Indicate that the process should be elevated $newProcess.Arguments = "& '" + $script:MyInvocation.M圜ommand.Path + "'" # Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path # Create a new process object that starts PowerShell # We are not running as an administrator, so relaunch as administrator $Host.UI.RawUI.BackgroundColor = "DarkBlue" $Host.UI.RawUI.WindowTitle = $myInvocation.M圜ommand.Definition + "(Elevated)" # We are running as an administrator, so change the title and background colour to indicate this If ( $myWindowsPrincipal.IsInRole ( $adminRole ) )


# Check to see if we are currently running as an administrator # Get the security principal for the administrator role $myWindowsPrincipal = New-Object ( $myWindowsID ) # Get the ID and security principal of the current user account
