Skip to main content

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:
  • 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
  1. Open Windows Explorer.
  2. Navigate to the folder location the command prompt should load when first opened from the shortcut.
  3. 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.
  4. Now, type the letters cmd, which will automatically replace the selected text in the location bar, and press the enter key.
  5. 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.
  6. 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:
  7. 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.
  8. Click Apply and then OK.
  9. 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

  1. 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:
  2. The Properties window will open. Click on the Advanced button. 
  3. Check the box next to Run as Administrator.
  4. 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.


  1. 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.
  2. Go to the Start in: textbox and copy everything in it by selecting the text inside of it and pressing Ctrl C.
  3. Now go to the Target: textbox and add a space after cmd.exe and type /k
  4. Add a space after /k and then paste the text from the Start in: area that you copied using Ctrl V.
  5. Go to the first quote mark and press cd and a space inside of it so that it looks like the following image.
  6. Click OK.
  7. Now, you have a valid shortcut that will be launched with Administrator privileges and will open to the directory you want every time.
The /k switch forces the system to go to the specified target location after granting Administrator rights to the program.

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 Morton

Comments

Popular posts from this blog

How To Solve The 'sudo' is not recognized as an internal or external command, operable program or batch file Message

Recently, I was talking with a developer about  sudo and how they initially didn't realize what sudo was. The developer had never worked on anything other than computers running Microsoft Windows. That gave me the idea for this little programming tip on the alternative to sudo when you are using a Windows machine. First, some history. Sudo can be called the one command to rule them all when you are working on a Unix based system. In fact, it really IS the one command to rule them all on those types of systems! Sudo is pronounced "sue dough" and it stands for "super user do" or "substitute user do". It is a program that allows you to run programs with the security privileges of another user. That user, by default, is the superuser for the machine you are on - hence, the original meaning of "super user do". The sudo program was enhanced to include the ability to run commands as other special users - not only as the superuser - hence ...

How To Solve Connection attempt failed with "EAI_NONAME - Neither Nodename Nor Servname Provided, Or Not Known

If you have ever tried to import a file into FileZilla from your domain host only to find that using the supplied settings produced the, Connection-attempt-failed-with-EAI_NONAME---Neither-nodename-nor-servname-provided-or-not-known".   error, you are in luck. I am going to show you a quick way to take care of this issue. When you are using an FTP client to connect to your site, you typically have a setup that looks something like this. (Note - if you are using FileZilla, your screen looks EXACTLY like this, since this is the ftp client I am using here.) Notice the area I have highlighted in Yellow. This is the problem child in this scenario. Although your hosting company may have stated that you should use ftp.YourWebsite.com, that is often NOT the correct thing for you to use to gain remote ftp access to your site. The error means that the program cannot resolve the dns entry for your site. Instead of using ftp.YourWebsite.com, you need to replace the host ftp.YourWeb...

How To Reset Your Entry Processes Or How To Clear Your Entry Processes In A Shared Hosting Environment Using CPanel

One of the most frustrating things is to wake up one morning and discover that your website is down (a 508 error) and you don't have a tool to get it back up and, instead, have to contact your hosting company to reset things for you. Sometimes, if you are using a content management system, the issue may be something as simple as a plugin. Do you really want to have to reach out to your host every time you have an issue? If you don't, I am going to show you one way to get your account back up and running. This will not work for everyone, but if you are using certain technologies, it will work for you. What you will need: Access to your cPanel. An account running PHP ISSUE: You have used up all of your allocated server resources and your site is now experiencing a 503 or 508 error and is not allowing any traffic to reach your site. SOLUTION: Log into your cPanel account. If you do not have a cPanel account, this won't work for you. Search for Select PHP Versi...