How to run exe with / without elevated privileges from PowerShell

I would like a simple way to start a process with different privileges from the same user without asking or not knowing his password. If necessary, the dialogue will be in order. I would prefer not to run the PowerShell subprocess to accomplish this.

Scenario 1: The PowerShell script runs in administrator mode. I want to run a script or .exe without administrator rights, but with the same user.

Scenario 2: The PowerShell script runs as usual. I want to run a script or .exe with administrator privileges for the same user.

+4
source share
1

.

, :

$CurrentID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$CurrentPrincipal = new-object System.Security.Principal.WindowsPrincipal($CurrentID)
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator

# Check to see if session is currently with admin privileges

if ($CurrentPrincipal.IsInRole($adminRole)) {
    write-host "Yes we are running elevated."
}else{
    write-host "No this is a normal user session."
}

, , , :

$newProc = new-object System.Diagnostics.ProcessStartInfo "PowerShell"
# Specify what to run
$newProc.Arguments = "powershell.exe"
# If you set this, process will be elevated
$newProc.Verb = "runas"
[System.Diagnostics.Process]::Start($newProc)

, , , ...

. , , .

: "" . .NET/PowerShell . ( 12 COM-). vista-7-uac-how-to-lower-process-privileges .

, , "" explorer.exe. .exe, explorer.exe, .

$newProc = new-object System.Diagnostics.ProcessStartInfo "PowerShell"
# Specify what to run, you need the full path after explorer.exe
$newProc.Arguments = "explorer.exe C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
[System.Diagnostics.Process]::Start($newProc)

EDIT # 2: , , - runas.exe 0x20000 ( ):

C:\> runas /showtrustlevels The following trust levels are available on your system: 0x20000 (Basic User) C:\> runas /trustlevel:0x20000 devenv

enter image description here

+5

All Articles