In Windows Operating Systems, some tasks which are critical for the Operating System to run, can be performed only by Administrators. Same rule is applicable for Windows Server 2022 also. A normal Windows user cannot run programs, or run commands from PowerShell, which can cause system wide effects.
Windows User Access Control (UAC) is one of the important security features in Windows, which prevents unauthorized changes to the Operating System, its files or configuration by unauthorized users.
In this example, I want to configure an IPv4 address to Windows Server 2022. Changing IPv4 address by an unauthorized user can cause serious negative implications to the Operating System, or its users. Changing IP address requires administrative level permissions in Windows Server 2022. A normal Windows user cannot perform this task.
To understand the concept of Windows User Access Control (UAC), please refer below images. Below image shows a PowerShell console, which shows current user as "jajish", who is not an administrator. The command used to find the current logged-in user is "whoami".
Now, the user "jajish" (who is not an administrator) is trying to run a PowerShell cmdlet to configure an IPv4 address. The PowerShell cmdlet to configure a new IPv4 address is shown below.
New-NetIPAddress -InterfaceIndex 3 -IPAddress 192.168.10.203 -PrefixLength 24 -DefaultGateway 192.168.10.1
Following image shows that PowerShell displaying an error, showing that, the operation is not permitted.
Now, let us try to run PowerShell as local Administrator, and then run the same PowerShell cmdlet.
How to run a program as administrator from Desktop short cut
To run a program as Administrator from Desktop, first create a short cut for the program at Desktop, right-click the short cut, and click "Run as administrator" from the context menu, as shown below.
Now enter the password of the user "administrator", when prompted. Click "Yes" button after entering the password.
A new PowerShell window is opened as user "administrator". You can again check who is the current user, bye running "whoami" command.
Now, again run the above permission denied "New-NetIPAddress" cmdlet, which required elevated permission. You can see that the cmdlet executed successfully as user "administrator".
How to use Start-Process cmdlet to run a program as administrator
You may also use "Start-Process" PowerShell cmdlet to run a program as administrator. Use below command to run a program as administrator, using "Start-Process" PowerShell cmdlet.
Start-Process -FilePath C:\Windows\System32\cmd.exe -Verb runasuser
Refer following screenshot to understand the "Start-Process" PowerShell cmdlet more clearly. In this example, I am trying to run command prompt (cmd.exe), which is located in "C:\Windows\System32\" folder as a different user (administrator).
Now the Windows User Access Control (UAC), will prompt for the user id and password. Enter administrator user id and its password, as shown below. Click "OK" button to run the program as administrator.
You can see that the command prompt program (cmd.exe) is run as user "administrator", as shown below.
How to run a program as administrator from Windows Taskbar Search Box
You may run a program as administrator from Windows Taskbar Search Box. To run a program as administrator from Windows Taskbar Search Box, just search for the program from Search box, then right-click the search result and select "Run as administrator" from the context menu. Please refer below image.
How to run a program as administrator from Windows Run box
Another way to run a program as administrator is to run it from Windows "Run box". You can open Windows run box by right-clicking Windows start menu button, and then by clicking "Run" from the context menu. You can also open "Run box" by pressing Windows key + R key together from Windows Desktop.
Once the Windows "Run box" is open, type-in the program to run, and then hit Control + Shift + Enter keys together.
Windows User Access Control (UAC) will prompt you to enter administrator password. Type-in the administrator password, to run the program as administrator.
Written by Jajish Thomas.
Last updated on 20th May, 2022.