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:\Windows\System32\drivers\etc\hosts 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.
- Enter runas command string in the dialog:
- Enter the administrator password to let OS authenticate the credentials.
- The command is executed as administrator.
You can see a Run Dialog is opened.
runas /user:\administrator "notepad %SystemRoot%\System32\drivers\etc\hosts"
If we want to run the command in another computer, we should indicate the computer name.
runas /user:ED-COMPUTER\administrator "notepad %SystemRoot%\System32\drivers\etc\hosts"
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.
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%\System32\drivers\etc\hosts"
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.
Or put it in a Windows Explorer address line.