What is the quickest way to get elevated rights in powershell? - windows

It happens again and again that I am in a Powershell session and want to execute a command for which I need admin (elevated) rights.
My current workflow then:
1. pwd (ctrl+c)
2. open a new Powershell (run as administrator)
3. cd ctrl+v
This is very annoying and time-consuming, how can I optimise this?

I guess the standard way of creating a shortcut should do it:
In a command box type where wt.exe to get the file path.
This will most probably return C:\Users\<yourname>\AppData\Local\Microsoft\WindowsApps\wt.exe
Open the path and right-click wt.exe (eventhough in there it shows 0 kb)
Select 'Create Shortcut'
Right-click the new shortcut and in the General tab change the name to Windows Terminal (Admin)
In the Shortcut tab, click the Advanced button and check the box "Run as administrator"
click OK
Drag the shortcut to your desktop

Theo's answer didn't work for me, but this one did. Copied:
Right click -> New -> Shortcut
Type in C:\Windows\System32\cmd.exe /c start /b %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\wt.exe for the location
Give whatever name you want to give, finish.
List item
Right click on the newly created shortcut -> Properties -> Advanced -> Run as administrator

Related

Using cmder . Windows 10

I downloaded Cmder on my PC but I want that the cmd starts on a folder as then I can navigate because if not the cmd starts in the Cmder folder and I can't go anywhere. Can someone help me, please? Wish you understood me!
Very simple and best way to get CMDER wherever you want is adding it to de Windows Context Menu (right click).
Open a terminal as an Administrator
Navigate to the directory you have placed Cmder
Execute .\cmder.exe /REGISTER ALL
If you get a message "Access Denied" ensure you are executing the command in an Administrator prompt.
In a file explorer window right click in or on a directory to see "Cmder Here" in the context menu.
From: https://github.com/cmderdev/cmder#shortcut-to-open-cmder-in-a-chosen-folder
Tip: put the CMDER files in c:\Program Files\CMDER
If I understood you correctly, you want to change the directory you start from each time you open a new terminal.
To do that:
click Win+Alt+t to open the settings
In the settings group 'Startup' choose 'Tasks'
Choose the console you want to modify (e.g. cmd::Cmder, cmd::Cmder as Admin, etc..)
Click the 'Startup dir...' button
Select the directory you want the console to startup in by default
Enjoy!
You dont give us much to go on but you should have a shortcut with which to start cmder perhaps on your desktop something like this.
If not find your installed copy of cmder.exe then Right Click it then select Send To
and then finally select "Desktop (as shortcut)"
Right click the shortcut and select Properties of that shortcut and then add your prefered starting DIRectory after a /start DIRective
If you want to Autorun other start-up commands see
https://stackoverflow.com/a/68185482/10802527

Is there a way to open command prompt in current folder?

I have a project folder somewhere, and many times I need to open command prompt (on windows 7/8.1/10) and cd to that folder. It would be very handy if there's an option right click > open cmd here.
is there a tool for that?
Just go to your folder location and type "cmd" on the address bar.
Press Shift + Menu, then choose Open Command Window Here. It works.
In win7/8, try right click while holding shift key, should have cmd prompt here
How about to use the PowerShell OpenHere module?
Run PowerShell with elevated permissions and type:
Install-Module OpenHere; Import-Module OpenHere
Set-OpenHereShortcut -ShortcutType:WindowsPowerShell
Disclaimer:
I'm a developer of this module.
use the description in https://stackoverflow.com/a/34534874/1498669 and put "run as administrator" checkbox on
Open 'File Explorer' and enter "shell:sendto" in location bar + hit return to get into this folder
Right mouse click and create a "New"->"Shortcut", put cmd.exe into the path, done
Edit the properties of the shortcut and edit the target to "%windir%\system32\cmd.exe /k pushd"
you can also create a copy of that shortcut, rename it to cmd.exe_admin, select properties, hit button "Advanced" an select the checkbox "run as Administrator"
Now use the "SendTo"-submenu in the explorer right click context menu to send any filepath or folder into the normal or elevated commandbox.
This "shell:sendto"-trick is also very useful for eg. Notepad++ or any program you want to start in "elevated" mode.
Type cmd command in address bar where path or location of the file or folder is shown.

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.

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.

Batch: start application doesn't show a GUI

I try to launch a self written autoit application called "KeyShortcuts.exe" using a batch called "launchMacros.bat". This applications provides keyboard shortcuts for various things and includes a GUI which shows me the available shortcuts.
launchMacros.bat:
start "MyMacros" "M:\applications\AutoIt\KeyShortcuts.exe"
The application does start and I'm able to use every shortcut but I'm not able to see the GUI.
If I start the application direct (double click on KeyShortcuts.exe) everythings works fine.
I also tryed starting the application using runas:
runas /user:REQUIREDUSERNAME /savecred "M:\applications\AutoIt\KeyShortcuts.exe"
Same problem here. Even right click -> "Run as administrator" doesnt worked.
Any suggestions?
If your batch file is in a different directory than KeyShortcuts.exe, you may need to specify the starting directory using the /D parameter for START.
Like this:
START "MyMacros" /D "M:\applications\AutoIt" "M:\applications\AutoIt\KeyShortcuts.exe"
Every batch file launched from Windows GUI create a new console window, run the batch file, then close. If you need this to be different, there's several ways:
Create a shortcut to CMD /K YOURBATCHFILE.BAT
Add a pause to your BAT file
Here's a demonstration of method 1:
New > Shortcut
Type the location of the item: C:\Windows\System32\CMD.EXE
Type the name for this shortcut: InsertYourNameHere
Click Finish
Right click on your Shortcut and go properties
Change Target to: C:\Windows\System32\CMD.EXE /K "InsertYourBatchFileName.BAT"
Click OK
Done, now you have a shortcut that opens a new console window and leaves it open whilst ir runs your batch file.

Resources