Always run cmd via ConEmu as administrator - cmd

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.

Related

How do I change my VS Code terminal to cmd.exe instead of powershell?

For some reason my VS Code terminal is Powershell instead of cmd.exe. In my Terminal > External: Windows Exec is set to C:\WINDOWS\System32\cmd.exe. However, when I open the Terminal in VS Code I see PS C:...>. Also, in the terminal drop-down I only see powershell as an option.
How do I switch the Terminal to CMD.exe? Or maybe my better option would be to add cmd.exe to the list of available terminals so I can switch between them?
Open File -> Preferences -> Settings
Select User Settings in upper right corner.
Add the following line
"terminal.integrated.shell.windows": "cmd.exe"
Source: https://blog.jongallant.com/2017/02/vs-code-integrated-terminal-powershell-default-change-to-cmd/
To version
First step:
Second step: select the desired option:
Or
"terminal.integrated.defaultProfile.windows": "Command Prompt"
You can use View / Command Palete / Terminal: select default terminal to select from the range of detected terminals. Mine shows PS and cmd.exe which had to be changed as PS is disabled as a security policy in our environment.
In a recent VS Code upgrade the command prompt path in the profile config was updated as well - terminal.integrated.profiles.windows
This article mentioned how you can reset that.
https://dev.to/andrewriveradev/how-to-set-git-bash-as-integrated-terminal-in-vscode-2k31
Open command palette (CMD + Shift + P)
Search "Preferences: Open User Settings (JSON)"
Delete the terminal.integrated.profiles.windows object from the config
Create a new field by typing "" (double quotation key). Inside the quotation type "terminal." a list of options will appear.
Select terminal.integrated.profiles.windows. When you select terminal.integrated.profiles.windows it will be expanded
Add or replace "terminal.integrated.shell.windows": "cmd.exe"
To add onto LeSchlongLong's answer, which is now deprecated, you can simply follow these steps to change the default profile:
Ctrl+Shift+P (Windows) / Cmd+Shift+P (Mac)
Search for "Terminal: Select Default Profile"
Select whichever profile you would like to use

How to run cmd as admin

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

How to create AutoHotKey which starts script (i.e .bat) using Cmder command line arguments?

I am trying to create an autohotkey which starts a script (i.e .bat):
#!g::
Run "Path\To\script\script.bat" debug
Return
The AutoHotKey works properly. However, I would like the .bat to be opened using Cmder instead of the default windows cmd.
I tried to set the Cmder as the default cmd by going to Settings-> Integration -> Default term and by checking the "Force ConEmu as default terminal for console applications", but this did not change anything in my particular case, and the script is still being ran in windows cmd.
Assuming Cmder can take a command line parameter, make it explicit:
Run "Path\To\exe\Cmder.exe Path\To\script\script.bat" debug
Else, run Cmder and then use AHK to file open the script.
EDIT: Based on OP's solution, could try:
Run "Path\To\exe\Cmder.exe /Task ""Path\To\script\script.bat debug"""
or
Run "Path\To\exe\Cmder.exe /Start ""Path\To\script"" /Task ""script.bat debug"""
The exact syntax and whether and where to surround things with quotes is tbd, but try and see.
In the end I used below script to make it work:
; Win+Alt+y - Start script
#!y::
Run "d:\cmder\Cmder.exe" "d:\somePath\FolderContainingTheBat\"
sleep 1000
send script.bat debug{enter}
Return
EDIT
Another solution for this does not involve AutoHotKey and works only with default windows cmd. I did the following:
Create a .bat file which contains the following
script.bat debug
Create shortcut for the newly created bat file and assign to it a "keyboard shortcut": Right click on the created shortcut -> Properties -> "Shortcut" tab -> Shortcut key
I made it work with this
Run, C:\path\Cmder\vendor\conemu-maximus5\ConEmu64.exe C:\path\to\script.exe

PhpStorm - run terminal (cmd) as administrator

On Windows it's easy to run cmd application as administrator:
Right click on cmd icon >> run as administrator`
But I would like to use PhpStorm terminal tool as administrator since I constantly have to execute queries that require administrator role.
When I open:
File >> Settings >> Tools >> Terminal
I can see that it is directly connected to cmd.exe and there are options to be filled:
And I see no checkbox with choice to run it as administrator.
QUESTIONS
Is it even possible?
If yes how do I do it?
Using settings or other way?
There are no options in the IDE for that at the moment: to run the shell (cmd.exe, powershell.exe etc.) with higher rights.
https://youtrack.jetbrains.com/issue/IDEA-121335 -- watch this ticket (star/vote/comment) to get notified on any progress. Maybe someone will post some possible workarounds there...
Your only option for now (that I'm aware of) is running IDE itself as Administrator -- Process Hacker tool confirms that both the IDE and cmd.exe will be run with elevated rights.
P.S.
For one time execution (or if you need to run IDE as normal user) -- have a look at this question and offered solutions: How to open an elevated cmd using command line for Windows?

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.

Resources