How to run cmd as admin - cmd

I use Windows 10 and in cmd I want to use the command
sfc /scannow
Cmd then gives me this message
You must be an administrator running a console session in order to use the sfc utility.
I then try to open cmd by right-clicking and press Run as Administrator.
But then I get this error. How can I solve this?

Firstly, the error is not related to cmd.exe running as admin. You probably have something incorrectly assigned to that specific shortcut.
Below is the correct way of running cmd.exe as Admin on Windows 8 and Windows 10
On your keyboard press windows key and X then select Command Prompt (Admin) from the list.
Alternatively right click on the start button and select the above mentioned.
This allows your to run cmd.exe as administrator. and you can then run
sfc /SCANNOW

Right-click on the Command Prompt icon and select Run as administrator

Related

Always run cmd via ConEmu as administrator

I'm using ConEmu and I want to always have my cmds run as administrator.
I've changed the settings that forces all my cmds to run through ConEmu, so typing 'cmd' in the Windows Run will open ConEmu (Settings -> Integration -> Default term -> Force ConEmu as default terminal)
I've tried changing the (Settings -> Startup -> Command line) to cmd.exe -new_console:a which works for shortcuts but doesn't change the default (running cmd from Run or opening a new tab inside ConEmu)
Thanks
For me it works to change the specified named Tasks in Settings->Startup to {Shells::cmd (Admin)}
ConEmu does not change the command you run. That would be strange, if you run from Win+R the cmd.exe and get started in ConEmu powershell.exe, for example. Isn't it?
Same with elevation level. ConEmu starts console application at the level user requested. This is the only logical behavior.
Want elevated cmd? Set up elevated cmd task as startup task for ConEmu and run ConEmu instead of cmd.
Well, alternatively, you may run from Win+R cmd -new_console:a or just call "run cmd as Administrator" to let ConEmu know what do you want exactly.
To elaborate on #Mike answer above , In the Settings window go to Startup menu item in the left pane . Now , in the main window there is a Specified named task drop down , select the admin option you want - for me it's {cmd::Cmder as Admin} . Click Save settings and now Cmder will open as admin every time .
Right click on ConEmu (x64) icon. Select Properties > Compatibility Tab > Check Run this program as administrator
I have check it on windows 10.
on win11, it worked for me to go into the settings in conEmu, startup>Tasks, select your previously created predefined task, i called mine Ubuntu::Bash, and the in the commands parameter box: %windir%\system32\bash.exe ~ -cur_console:p <<----this is what i had,
i added another line with an asterisk. "*"
new commands parameter arguments:
%windir%\system32\bash.exe ~ -cur_console:p
CONEMU settings screengrab
*
worked great.

How to open command prompt as administrator from address bar

I use address bar of File explorer to open command prompt in current directory(By typing cmd in address bar). It will open the command prompt as Administrator. I have used Windows 7 OS and I logged in as Domain Administrator.
Now I upgraded the OS to Windows 10. Now I am doing the same, But command prompt is not opened as Administrator.(For local Administrator account it was fine). Is there any way to get command prompt as Administrator(Opening from Address bar) ?
We can add this windows default shortcut for achieving cmd as Administrator in single click
Unfortunately a recent Windows 10 Update has removed the Open command prompt mentioned by #Arvindharaj. However, if you feel comfortable editing the Windows Registry then this site that explains how to activate admin cmd right-click option might be a great option. It was for me.
Here are basic steps after launching regedit.exe:
Go to this address: HKEY_CLASSES_ROOT\Directory\shell
Under this folder create a new key and label it runas.
Double-click the runas folder and check if there’s a “Default” key. Right-click it and choose “Modify.”
Once you click “Modify,” the “Edit String” box shows up. Type Open Administrator Command Prompt Here in the Value data box.
Next, in the same folder, create a new string value (right-click the runas folder and choose New and select String Value). Label it as NoWorkingDirectory.
Under the HKEY_CLASSES_ROOT\Directory\shell\runas path, create another key and label it as command.
Double click the folder and you’ll see the Default string value. Right click and choose “Modify.” Under the Value data, enter cmd.exe /k cd %1 and click OK.
FYI - I think this last step is wrong btw. The cmd prompt will launch as admin but in its default folder. So instead enter "cmd.exe /s /k pushd %V" and this should launch the admin prompt in the folder you right-clicked on.
I've tried #Alex's solution, but it still didn't work, CMD still evaluated without Administrator privileges.
I only have it working after running the following command in command prompt:
> REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
/v EnableLUA /t REG_DWORD /d 0 /f
And restart the Computer after this.
Can't say that this only helps, but maybe this in addition to #Alex's did the job.
Adding up to response from Aravindharaj G :
1> In File Explorer go to the window where you want to open PowerShell / Command Prompt
Use HotKey ( ALT (Hold) + F > S > A ) will open PS in that location.
2> Using Top Menu File > Open Command Prompt ( or Open Window PowerShell ) > Open Command Prompt as Administrator > now SELECT
"Add to Quick Access Toolbar"
This will add a Tiny icon in all File Explorer Windows for all.

Windows developer command prompt says I'm not administrator when I am

So I started the Developer command prompt in windows, and ran it as an administrator by right-clicking and choosing 'run as administrator.' It says Administrator: Developer command prompt right up there at the top. But when I ran an sn command. Windows responded Failed to read [file] because Administrator permissions are needed... I have a screenshot attached. Is there something else I need to do besides run the command prompt as an administrator?
I see what I did. I was doing sn on a directory instead of a file. When I did it on the file it worked just fine.

Running the cmd in windows command line as admin

Am opening windows cmd.exe as administrator and executing an installer(just call installer.exe) and it runs fine. But if I open the cmd.exe in normal mode ( not as administrator) but run the command as user administrator ( runas /profile /user:adminstrator installer.exe) am not able to execute the installer successfully.
The installer unpacks certain files in c:\users\ dir.
The error that I get is :
"Error running java -Dpython.console.encoding=UTF-8 -jar C:\users\<username>/tools/x.jar : Program ended with an error exit code. "
How can I solve this issue? Since am trying to automate executing this installer, opening the cmd.exe as admin is out of question. I would like to run the command as a normal user or if not possible, as an admin.
Am new to Windows. Any help is appreciated.
Thanks
You could create the .bat file with the line you want to run, then follow the procedures listed below to have it automatically run as an administrator.
Right click on the original file and click Create shortcut.
Right click on the shortcut and select the properties option.
Under the shortcut tab, click on the advanced button in the bottom right hand corner.
Check the box that says run as administrator
Click ok, and then ok.
Now when you double click on the batch file shortcut it will run as an administrator. You can delete the original if you wish to.

runas command in windows 7

I'm trying to run a batch file as admin. I found that I can use runas command which corresponds sudo command in Linux I think.
I tried
runas /noprofile /user:computername\adminuser "blah.bat start"
But it gives an error, saying :
Logon failure: user account restriction.. (msdos window doesn't allow me to copy anything) is there any way I can run this batch file as admin? Right click doesn't work because I can't include any parameters.
A workaround: You can create a shortcut to the batch file, add a parameter in the shortcut, then right-click to run the shortcut as admin.
Right-click the icon for the command-prompt and choose Run As Administrator. Then run you batch file from that window.
I believe that you can allow or disallow the RunAs command with the registry.
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer
"HideRunAsVerb"= 1
See Disabling the RunAs Command

Resources