Run Powershell script by a shortcut (as 'Admin')


abactuon

Well-known member
Power User
VIP
Local time
5:39 AM
Posts
1,484
OS
Microsoft Windows 11 Home
I used

0.webp

%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -ExecutionPolicy Bypass "E:\Example.ps1"

And in doing so, I had to specify

11.webp

Now for some reason it doesn't work.

1.webp

I had to specify this weird construct

%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -ExecutionPolicy Bypass -Command " Start-Process PowerShell -Verb RunAs \""-Command `\"" & 'E:\Example.ps1'`\""\"" "
 

My Computer My Computer

At a glance

Microsoft Windows 11 HomeIntel Core i5-13490F2 x 16 Patriot Memory (PDP Systems) PSD516G56...GIGABYTE GeForce RTX 4070 WINDFORCE OC 12G (G...
OS
Microsoft Windows 11 Home
Computer type
PC/Desktop
Manufacturer/Model
MSI MS-7D98
CPU
Intel Core i5-13490F
Motherboard
MSI B760 GAMING PLUS WIFI
Memory
2 x 16 Patriot Memory (PDP Systems) PSD516G560081 6400MT (32-37-37-74); 1.35V)
Graphics Card(s)
GIGABYTE GeForce RTX 4070 WINDFORCE OC 12G (GV-N4070WF3OC-12GD)
Sound Card
Bluetooth Аудио
Monitor(s) Displays
INNOCN 15K1F
Screen Resolution
1920 x 1080
Hard Drives
WD_BLACK SN770 250GB
KINGSTON SNV2S1000G (ELFK0S.6)
PSU
Thermaltake Toughpower GF3 1000W
Case
CG560 - DeepCool
Cooling
ID-COOLING SE-224-XTS / 2 x 140Mm Fan - rear and top; 3 x 120Mm - front
Keyboard
Corsair K70 RGB TKL
Mouse
Corsair KATAR PRO XT
Internet Speed
100 Mbps
Browser
Firefox
Antivirus
Microsoft Defender Antivirus
Other Info
https://www.userbenchmark.com/UserRun/66553205
I don't have the same problem. Giving admin rights to my shortcut always triggers UAC (unless I lower the setting).

This is my test script:
Code:
$CurrentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())

if ($CurrentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    "You have ADMIN rights."
}
else {
    "You don't have ADMIN rights."
}
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
Back
Top Bottom