How To Create A Command Prompt Shortcut That Runs As An Administrator And Opens To A Specific Location Using Microsoft Windows
We often create shortcuts to items we frequently use as we work. These shortcuts can live on the desktop, on the start menu or on the taskbar, where we most frequently use them. When you set up a command shortcut, it is often with the intent of working within a specific directory. Navigating a the structure of a directory is simple to do in a command prompt. You can use cd to get to a specific location once the command prompt is open.
For example, if you are in the c:\, the following will take you to the places specified:
For example, if you are in the c:\, the following will take you to the places specified:
- cd windows will take you to C:\windows>
- cd windows\system32 C:\Windows\System32>
- cd.. will take you down one level to C:\Windows>
- cd\ will take you down to the root level
This is fine, but when you initially launch the command prompt, you may not want to navigate around each and every time. There is a simple way to create a shortcut that will take you exactly where you want to go each and every time. You may also have a situation where you need to run your command prompt with elevated Administrator privileges each and every time you use it. This is also simple to create. However, if you want to create a command prompt shortcut that takes you to a specific place and is also run with elevated Administrator privileges, initially you are going to hit a roadblock.
If you already have a shortcut set up and you add Administrator privileges, the directive that makes the short cut start up in a certain place is ignored and the command prompt will always start in the system directory. This is a security measure taken by the system to prevent a current directory attack and it happens because the location to open (Start in) is determined and set before the Administrator privilege is applied. When the Administrator privilege is applied, it wipes out the Start in value and kicks you back into the system directory. I wouldn't say it is a foolproof method of protection, because it isn't, but it is one way to decrease the likelihood that you could execute a rogue program inadvertently from the directory you are working in with elevated privileges. As with all things protective, however, there is a workaround. I will break this down in individual steps, so if you only need one part of this, you can get what you need and move on.
STEP 1 - CREATING A COMMAND PROMPT SHORTCUT THAT ALWAYS OPENS TO A PARTICULAR DIRECTORY LOCATION
STEP 2 - RUN THE COMMAND PROMPT SHORTCUT AS AN ADMINISTRATOR EVERY TIME IT IS OPENED
STEP 1 - CREATING A COMMAND PROMPT SHORTCUT THAT ALWAYS OPENS TO A PARTICULAR DIRECTORY LOCATION
- Open Windows Explorer.
- Navigate to the folder location the command prompt should load when first opened from the shortcut.
- Once in the folder, click inside of the open area toward the end of the location bar somewhere after the text. The entire location should then show selected. Make sure you have the entire location selected and press Ctrl-C.
- Now, type the letters cmd, which will automatically replace the selected text in the location bar, and press the enter key.
- A command prompt window will pop up. Go to the taskbar and right click on the icon for the command prompt window and select Pin to taskbar.
- Now, right click on the icon for the command prompt window that you pinned to the taskbar and when the context menu opens, right click again on the name of the item and then select Properties. The menu structure should look something like this:
- The Properties window will open. Select everything in the textbox next to Start in:, right click and then select Paste or press Ctrl V on your keyboard.
- Click Apply and then OK.
- You have now created a command prompt shortcut that will take you directly to the directory location you want every time you open it.
STEP 2 - RUN THE COMMAND PROMPT SHORTCUT AS AN ADMINISTRATOR EVERY TIME IT IS OPENED
- Now, right click on the icon for the command prompt window that you pinned to the taskbar and when the context menu opens, right click again on the name of the item and then select Properties. The menu structure should look something like this:
- The Properties window will open. Click on the Advanced button.
- Check the box next to Run as Administrator.
- After checking the box, click OK.
STEP 3 - MAKE THE ADMINISTRATIVE COMMAND PROMPT OPEN TO THE LOCATION WE ORIGINALLY SPECIFIED
As stated earlier, when you set up the command prompt to execute with Administrator rights, the Start in: parameter is no longer used because the Administrator rights are applied AFTER the Start in: parameter is set. I will show you how to reset it so that it will be recognized.
- Go back into the Properties screen by right clicking on the icon on the Taskbar and then right clicking on the name of the item and selecting Properties.
- Go to the Start in: textbox and copy everything in it by selecting the text inside of it and pressing Ctrl C.
- Now go to the Target: textbox and add a space after cmd.exe and type /k
- Add a space after /k and then paste the text from the Start in: area that you copied using Ctrl V.
- Go to the first quote mark and press cd and a space inside of it so that it looks like the following image.
- Click OK.
- Now, you have a valid shortcut that will be launched with Administrator privileges and will open to the directory you want every time.
Please Note : If you are interested in just getting this done, you can do Step 2 and Step 3 at the same time by opening the Properties window, setting the Administrator information and setting the Start in: parameter. I walked you through the steps separately so you can know how to do each one apart from the other.
Enjoy!
-Kila MortonEnjoy!
Comments
Post a Comment