Generally, we do not log on Windows as Administrator to do routine jobs, though we are in Administrator group. We usually use a normal user, like steven to finish our daily works. At times, you may need the privilege of Administrator to do something unusual.
For example, in some cases, we need to modify C:WindowsSystem32driversetchosts for resolving our own domain names in LAN. But this file is read-only for security reasons, which means you can read but you can't write, rename or delete. You need Administrator privilege to finish the task.
You don't have to actually leave current account and log on as Administrator, you can acquire Administrator privilege on demand. Let's do it step by step:
Press ⊞ Win + r to Open a Run Dialog.
Open a Run Dialog
You can see a Run Dialog is opened.
A Run Dialog
Enter runas command string in the dialog:
runas /user:administrator "notepad %SystemRoot%System32driversetchosts" If we want to run the command in another computer, we should indicate the computer name. runas /user:ED-COMPUTERadministrator "notepad %SystemRoot%System32driversetchosts"
Enter runas command in Run Dialog
To customize for your own tasks, please replace ED-COMPUTER with your computer name, and type your command inside the pair of double quotes.
For more examples, you can refer to Microsoft TechNet Library: TN Runas
Enter the administrator password to let OS authenticate the credentials.
For batch files or scripting purposes, you can add an option /savecred in the command line to skip the authentication step if the account had been ever authenticated: runas /user:administrator /savecred "notepad %SystemRoot%System32driversetchosts"
The command is executed as administrator.
Now, you will see the notepad opened as an administrator. You can modify the file and save.
This is how we run as Administrator in command lines on Windows. Actually, Run Dialog is not the only place that you can put the runas command string, you can put it in a CMD Dialog also.