Showing posts with label Shell Utilities. Show all posts
Showing posts with label Shell Utilities. Show all posts

Monday, April 12, 2010

Shell Utilities – Customize Run Commands

A pretty good feature i like in windows is the "Quick Launch bar", to which I got adding my frequently used applications, making it a pretty long one. As time went by my "Quick Launch" grew along and at last got fully packed, now every program shortcuts is vying to get into that precious space.


Finally time had come to look for other options, to get programs accessible in a short gesture. I Googled on this very trivial problem. The solutions that poured in had options varying from shortcut managers, keyboard combinations, hidden windows the list goes on and on. 


While moving through the start menu, the "Run" item, caught my attention. It was a like a eureka feeling, once i explored the possibilities that this little window offered, i was now sure this is the one which could solve my "Quick Launch" crowding dilemma. 


So we are going to straight away jump into the solution part and here we go.


My curiosity was, where does this commands for "Run" were stored in? After some research, i came up with a set of answers.


1. Registry
2. Path Environment Variable


Whenever we key in a text say "mspaint"(without quotes) into the "Run" dialog, it first probes for the exact term in windows registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths if not found, next it probes the locations\paths specified in the "PATH" environment variable. If didn't find in any of the above locations, it givesup and says "Sorry man, i didn't get you what you meant" (something similar)


Now lets create a handy command for Internet Explorer, which most of you might be using frequently as I do. Some of you might already know that, Internet Explorer has a command mapping named "iexplore"; i.e; if you key-in iexplore into the "Run" window, you can open up Internet Explorer. We are going to abbreviate it to just two letter, i.e; "IE"(without quotes), here how its done.


1. Fire-up windows registry (enter "regedit" inside "Run" window)
2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
3. Under "App Paths", create a new "Key" named "ie.exe"
4. Select the newly created key "ie.exe"
5. On the right pane, you will find a "(Default)" key, double-click that.
6. Provide the absolute path of Internet Explorer.
Example: "C:\Program Files\Internet Explorer\IEXPLORE.EXE"

7. Click "OK" and you are Done.


Now open "Run" window and key in "IE"(without quotes) and press enter, hey its Internet Explorer in front of you.


Now lets see the other way to create custom Run commands. This is done by creating batch files with the command name of your choice, here i am going to show you how to create a custom Run command for Firefox browser with the command name "FF".


1. Open-up the Command Prompt
2. Key-in "PATH" (without quotes), now you will see a listing of locations set by different applications.
3. Goto any of the locations listed out by "PATH" variable. For time being, i am using the "system32" folder.
4. Create a batch file name "ff.bat"(without quotes)
5. Edit the batch file and specify the absolute path where the "firefox.exe" executable is located.
Example: "C:\Program Files\Mozilla Firefox\firefox.exe"
6. Save the batch file. You are done.


Now you can key-in "ff" (without quotes) into the "Run" window, to see firefox opening up.


I am sharing a list of custom commands which i had created for myself, Please make sure you create the registry mapping to get this working.


np Notepad
msp MS Paint
npp Notpad++
vs Visual Studio
ie Internet Explorer
ff Firefox
gc Google Chrome
xls Excel
doc Microsoft Word
ppt Microsoft Power Point
sqldb SQL Server Management Studio
odb Oracle SQL Developer
mpp Microsoft Project
sp Share Point Server
sc Source Control
mp Memory Profiler
pe Process Explorer
pm Process Monitor
ar AutoRuns
mail Microsoft Outlook
gimp Gimp Image Editor







Some days back my pc crashed and i had to  create all my custom commands from scratch, which itself was a quite lengthy and mundane one. I am now thinking of to come up with a free utility to automate this process and additionaly to export and import custom command settings. You can definitely expect this soon.



Sunday, April 11, 2010

Shell Utilities – Visual Studio Command Prompt



Have you ever wished for a feature, similar to “Open Command Window here”, for “Visual Studio Command Prompt”? If yes jump in.


Any developer, who frequently use “Visual Studio Command Prompt” for command line compilation or for other related tasks, might have faced with the dilemma of navigating to the directory where the source code is located. Even though this is trivial task, I like to make things even simple and better.

When you open the "VS.NET Command Prompt" you will notice that, by default the path points to where Visual Studio is installed, making our task of pointing to the directory of our choice a bit tedious. I decided to iron out this irksome step; the solution that immediately turned up in my mind was similar to the one in my previous post “Shell Utilities – The Command Prompt”.


If the above download link didn’t work, follow the given steps
  1. Copy the below text and save it to a batch file named “vsnet2008.bat” (save to C:\ drive, or in any drives root like D:\, F:\ etc)




    @cd %1
    @COLOR 0A
    @%comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
  1. Copy the below text and save it to a batch file named “VSCmdPrompt.reg” (to any location you wish)



Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\VSCommandPrompt]
@="Open VS.NET 2008 Command Prompt"

[HKEY_CLASSES_ROOT\Directory\shell\VSCommandPrompt\command]
@="C:\\vsnet2008.bat %L"

Execute the following steps to get things rolling.
  1. First of all, you need to have “Visual Studio.Net” installed in you PC.
  2. Secondly you need to have admin rights, which i presume for every developer.
  3. Extract the zip file downloaded from the above link(if you couldn't download, skip this step.)
  4. Open “VSCmdPrompt.reg” and “vsnet2008.bat” in notepad (I prefer Notepad++)
  5. Open the “Properties” dialog for “Visual Studio Command Prompt”.
    (You can find in “Start
    à Programs à Microsoft Visual Studio 2008 à Visual Studio Tools à Visual Studio 2008 Command Prompt”)
  6. Copy the contents in “Target” field; under “Shortcut” tab.
    it should look like the following for 32-bit systems; for 64-bit systems the x64 will be shown in place of x84.



  7. %comspec% /k ""J:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
  1. Open “vsnet2008.bat” in editor and overwrite the third line with the copied contents. Make sure the “@” character is not overwritten.
  1. Save the batch file, make sure the batch file is in the root drive. (say C:\, D:\, F:\ etc)
  1. Open “VSCmdPrompt.reg” in editor; specify the path where the batch file is located. If you had saved the batch file in a root drive, then you just needed to change the drive letter.
  1. Save the “VSCmdPrompt.reg”.
  1. Double click the “VSCmdPrompt.reg” file. Click “Yes” for the confirmation message. You are Done, thats all.


Now you should be able to trigger "VS.NET 2008 Command Prompt" from any directory of your choice.




Shell Utilities – The Command Prompt

Have you ever been into a situation, where you had to open the command prompt, and navigate to a directory deep by entering the drive name and after that keying in all those colossal paths into the prompt to get there, pretty tough uh..?  I really get crazy doing this kind of things.



Fig 1.


After Googling, I came out with handful of interesting solutions to this mundane task.

1. Microsoft – “Open Command Window Here”. This was the best solution I came across (and the frequently used), to quickly open a command prompt from the directory of choice. Microsoft “Power Toys for Windows XP” is providing a FREE utility called “Open Command Window Here”. You can grab a copy for yourself from the link below.

Once installed, you will find a new item named “Open Command Window Here” under the “context menu” as in Fig 2. Now this made things get done in a jiffy, I just need to right-click the folder and select “Open Command Window Here” from the context menu, boom!!! the Command Prompt shows up with the folder you had selected. That’s it.







Fig 2.


2. “Tab” key to the rescue. I really found this “Tab” feature quite handy, before I came to know about the “Open Command window here” utility. In the screen (Fig 1), instead of keying in the entire directory name, say “CLRProfilerTest”(The colossal one, for me) you can key in the first few alphabets like CLR and press “Tab” key to auto complete it for you. If you have multiple directories with the same name (say “CLRProfilerDemo” and “CLRProfilerTest”), repeatedly press the “Tab” key to show up each directory name, until the directory you need is displayed. This one is a real time saver, when struggling with huge directory names. Pretty elegant solution.

3. Behind the scenes – I was wondering how the “Open Command window here” was handling this simple but quite handy feature, which made me to dig into the windows DNA (The Windows registry). Eureka!!! Its there, I found out. Fireup(keyin) “regedit”, from Start->Run(WARNING: Don’t create\alter any settings in registry, if you are not sure what that’s for). 
Navigate to “My Computer\HKEY_CLASSES_ROOT\Directory\shell”. You will see like the one in Fig 3.










Fig 3
Voila. Here's the code for this pretty cool utility. You can see the value cmd.exe /k "cd %L" What this code does is, it opens Command Prompt by passing two parameters. First one is "/K" which tells the cmd.exe to interpret\execute the  second parameter. The second parameter "cd %L" is a change directory command (inbuilt command) followed by the "%L", which passes the absolute path of selected directory.  executing the command will look like the following, if the selected directory location is "C:\Windows\System32"



cmd.exe /k "cd c:\windows\system32"

like this you can create custom commands for the directory as you wish.

If you cant get the “Open Command Window Here” utility. Here is pretty simple hack (works only if have admin rights), just copy and paste the below text to a notepad, save the file with a .reg extension (say OpenCommandPromptHere.reg). 

Windows Registry Editor Version 5.00


[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="Open Command Window Here"

[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="cmd.exe /k \"cd %L\""

Double click the file (the .reg file you just now created), click “Yes” for the confirmation, that’s it. Now the “Open Command Prompt Window here” will get listed in your context-menu while right-clicking directories under windows explorer.