Wednesday, April 28, 2010

Prim and Proper way to ASP.NET Sessions

After being to the web domain, I felt a bit uneasy by the way Sessions were handled in ASP.NET; more or less the session class was like a universal adapter, where you can plug in data-types from primitive types to reference types. At first glance, it might seem like a boon, but the devil is in the details; as soon as the development phase scales up, this very handy feature could turn out to be a nightmare, if not properly dealt with.

Here I had compiled some common issues, while dealing with raw ASP.NET session objects.
  • Session Name Typo - This is a common issue, where a session name say "AutomationID" created in PageA.aspx when accessed from PageB.aspx, might be inaccessible due to session name typo, when a developer accesses the session, by keying in "Aut0mationID". Here you can find a small typo, where zero is entered in, instead of the character "o". These sort of issues could eat up productive time and could even end up eating up others too. The straight forward solution for this is to use constants instead of using string literals. I recommend to create string constants to set and get values from session.
Here is the prim and proper solution for "Session Name Typo" issue.
public const string AUTOMATION_ID = "AutomationID";
//PageA.aspx
Session[AUTOMATION_ID] = 12;

//PageB.aspx
int Val = (int)Session[AUTOMATION_ID];
  • Session Datatype mismatch - This could happen when a value of type Int64 is set to a session and while accessing the same, the developer might unknowingly casts it to an 'int' (which in Int32 by default), which could lead to overflow bugs. The solution is to use strongly typed Session classes, which we are about to explore.
  • public const string AUTOMATION_ID = "AutomationID";
    //PageA.aspx
    Int64 AutID = 123456789000;
    Session[AUTOMATION_ID] = AutID;
    
    //PageB.aspx
    int Val = (int)Session[AUTOMATION_ID]; //Outputs -1097262584
  • Session Overwriting - This could occur when a developer unknowingly assigns a session name, which is already used by another session for keeping a value of different type. These could be sorted out through strongly typed session class.
  • public const string USER_ID = "UserID";
    //PageA.aspx
    Int64 UserID = 123456789000;
    Session[USER_ID] = UserID ;
    
    //PageB.aspx
    string username = "abcxyz";
    Session[USER_ID] = username; //Here UserID of type In64 is replaced with string.


By now a question might be popping-up in you mind like, why couldn't Microsoft provide a straightforward solution to this problem. Well before waiting for Microsoft to come out with a solution, lets jump into our own customized solution.


So now lets get on to the interesting part of creating a SessionParams class. Here we are going to create a static class named SessionParams for accessing the ASP.NET session in a intuitive object oriented way.


  public static class SessionParams
    {
        #region "Constants"
            private const string SESSION_PREFIX = "SESSION_PARAM_";
            private const string S_USERNAME = SESSION_PREFIX  + "USER_NAME";
            private const string S_AGE = SESSION_PREFIX  + "AGE";
        #endregion

        #region "Private"

        private static T GetParam<T>(string ParamName)
        {
            T Result = default(T);

            if (HttpContext.Current != null &&
                HttpContext.Current.Session != null)
            {
                if (HttpContext.Current.Session[ParamName] != null)
                    Result = (T)HttpContext.Current.Session[ParamName];
            }

            return Result;
        }

        private static void SetParam<T>(string ParamName, T Val)
        {
            if (HttpContext.Current != null &&
                HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session[ParamName] = Val;
            }
        }

        #endregion

        #region "Constructor"
        
        static SessionParams()
        {
            //Place any initialization code here.
        }

        #endregion

        #region "Public Session Params"

        //Sample Session properties  
        public static string UserName
        {
            get { return GetParam<string>(S_USERNAME); }
            set { SetParam(S_USERNAME , value); }
        }

        //Sample Session properties
        public static int Age
        {
            get { return GetParam<int>(S_AGE); }
            set { SetParam(S_AGE , value); }
        }

        #endregion        
    }


What you just saw is a strongly typed session proxy class, which could be just accessed like any other static classes from ASP.NET pages and usercontrols. If you dig into the "SessionParams" class, you could see its a simple session wrapper. 


Now lets dissect the SessionParams class and see, what goes inside into this SessionParams class. The first thing is that, the SessionParams class is logically split to three regions like Constants, Private methods and Public properties.


The Constants region contains the names of session variables. While the Private methods region contains two generic methods namely "GetParam" and "SetParam" of both which receives a generic parameter. These two methods provide the core functionality of retrieving and assigning values to and from session variables; under the hood every public properties for this SessionParams is wrapping around these generic methods. Finally the third region the Public Properties. This is the place where you can access and define new session parameters for accessing, session values from ASP.NET usercontrols and pages.


The SessionParams class we had just discussed is having two sample session variables "Username" and "Age". Here's how to get and set values from the sample session variables.
string NameVal = "AlphaBeta";
int AgeVal = 25;

SessionParams.UserName = NameVal;
SessionParams.Age = AgeVal;

Response.Write(SessionParams.UserName);
Response.Write(SessionParams.Age);

Lets create a new param named "IsRegistered" of type "bool" inside the SessionParams class
  • First of all, you need to create a constant inside the constants region.
private const string S_IS_REGISTERED = SESSION_PREFIX  + "IS_REGISTERED";
  • There after, create a public property named "IsRegistered" of type bool inside region "Public Session Params" like the one below.
public static bool IsRegistered
        {
            get { return GetParam<bool>(S_IS_REGISTERED); }
            set { SetParam(S_IS_REGISTERED , value); }
        }
  • Thats it; now you new property "IsRegistered" is ready for action. Here's how its put into use.
SessionParams.IsRegistered = true;
Response.Write(SessionParams.IsRegistered);

Now we have a strongly typed SessionParams class in place, for interacting with ASP.NET sessions, which is to iron out the problems previously discussed. 


If you happen to encounter any issues with the SessionParams implementation, please let me know.


Monday, April 26, 2010

Impressions of Eyjafjallajokull Volcano

The Eyjafjallajokull volcano in Iceland was in the news headlines these days, crippling down the business and life's of millions. But what ever be the events, there is something pretty for the camera eye to capture on to. Here at Boston.com you can find some find some creative impressions taken from the very heart of the volcanic activity.



Thursday, April 22, 2010

C# Copy Property Values between Types


For a recent project, i came across a quite weird requirement. The requirement was to copy Public Property values in TypeA to TypeB. The criteria was that both the types should have the same property names, otherwise those properties will be skipped. The second criteria was that, it should copy nested types contained in a given source type. 


A word of caution. If you have Enums as properties, then both Enums in TypeA as well as in TypeB should share the same numerical values, even if Enum names are different. One more item is that, nested types should have the default constructor, else you should remove the "new()" generic constraint.


You can use this use the code below, if you come across similar sort of requirements. :)

    public static class Converter
    {
        public static void CopyProperties<T, Q>(T Src, Q Dest)
            where T : new()
            where Q : new()
        {
            foreach (PropertyInfo objSrcPI in Src.GetType().GetProperties())
            {
                PropertyInfo objDestPI = Dest.GetType().GetProperty(objSrcPI.Name);
                Object Val = null;

                if (objDestPI != null)
                {
                    if (objDestPI.PropertyType.BaseType == typeof(Enum))
                    {
                        Val = (int)objSrcPI.GetValue(Src, null);
                        Dest.GetType().GetProperty(objSrcPI.Name).SetValue(Dest, Val, null);
                    }
                    else if (objDestPI.PropertyType == objSrcPI.PropertyType)
                    {
                        Val = objSrcPI.GetValue(Src, null);
                        Dest.GetType().GetProperty(objSrcPI.Name).SetValue(Dest, Val, null);
                    }
                    else if (objDestPI.PropertyType != objSrcPI.PropertyType)
                    {
                        if (!objDestPI.PropertyType.IsValueType &&
                            !objDestPI.PropertyType.IsPrimitive &&
                            objSrcPI.GetValue(Src, null) != null)
                        {
                            Type objDestType = objDestPI.PropertyType;
                            Object objDest = Activator.CreateInstance(objDestType);
                            Val = objSrcPI.GetValue(Src, null);
                            CopyProperties(Val, objDest);
                            Dest.GetType().GetProperty(objSrcPI.Name).SetValue(Dest, objDest, null);
                        }
                    }
                }
            }
        }
    }

Using the CopyProperties procedure

    class A
    {
        public string FirstName { get; set; }
        public int Age { get; set; }
    }

    class B
    {
        public string FirstName { get; set; }
        public int Age { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            A objA = new A();
            B objB = new B();

            objA.FirstName = "Alpha";
            objA.Age = 12;

            Converter.CopyProperties(objA,objB);
        }
    }


Google Rolls Out "Governmental Requests" Service

If you wish to get a sneak preview of censorship and filtering requests Google had been receiving from different parts of the world, then read on.


Google had rolled out a new service called "Government Requests", which lists out statistics from different governmental agencies around the world all the way from, requests to pull down a service, removing content from Youtube, Blogger, Orkut; Data Requests etc. However Google itself agrees that the list provided through this service is not a comprehensive one, but they had tried their best possible to get the figures available to public. You can find statistics for most countries except from ones like China, which considers the requests itself as National secrets.


You can visit the service at http://www.google.com/governmentrequests/ 



Tuesday, April 20, 2010

SQL Intellisense

With the launch of SQL Server 2008 Management Studio (SSMS) a pretty sought after feature the "Intellisense" is now a built-in feature shipped with the editor. The feature dramatically improves the productivity by providing a auto complete list of table names after keying in the "FROM" keyword, similarly you will get a list of relevant column names after the "WHERE" clause. I really adore this feature; because most of the time either the table or column names are abbreviated which introduces a lot of typo as you keyin those SQL statements. 

I was glad to see this Intellisense feature and decided to try it out. After downloading the installation took more time than expected, I fired up the Management Studio but to my shock, i couldn't find the Intellisense in action. After going through forums i came to realize that, this feature works only with SQL Server 2008 server and not with down-version systems (like SQLServer 2005, 2000), but unfortunately at the time of this writing i was using SQL Server 2005 server, which doomed my expectations to get a preview of this very sought after feature. 

After a brief search, I came to find similar products offering the same feature; independent of SQL Server version. The first one that caught my attention was Red-Gate's SQLPrompt which provided Intellisense feature for SQL Management Studio regardless of SQL Server version. I was very much impressed by its features after going through its trial version, I really recommend it as a must to have productivity tool for any developer working with databases, but what made be pull back was its quite hefty price tag, for personal use. 

Later i stumbled upon a free product named "Toad for SQLServer", after the installation i was really impressed by what it had to offer. Its packed with features, much more than i expected. I am enumerating the features shipped with this freeware.

  • SQL Intellisense
  • Data Export Wizard
  • Code Snippets
  • Auto Correct for misspelled SQL keywords.
  • SQL Syntax Templates
  • SQL Execution Plan
  • Results Windows - Assists in Grouping, Sorting, Filtering.
  • Moreover this freeware version won't get expired as Toad Oracle Freeware does.






Saturday, April 17, 2010

A Truly Motivational Saga

I had a belief that only a sound financial background and knowledgeable parents could make their children to dream for the skies. But latter going through the biographies of some very eminent self made personalities, I came to realize that nothing is of a barrier from realizing your dream, be it monetary, physical or circumstances. If you have that craving desire and passion, then even failure couldn't stop you from achieving what you had envisioned. The only obstacles, one can see is the lack of focus, interest, willingness and at times even procrastinating the goals. Recently I came across a real life story which made this belief even more firm and I definitely recommend this as a "Must to Read".

In a remote village in Tamilnadu, a boy named Veerapandyan whose determination and passion got himself into, what is called as the steel framework of India, against all the odds. I assume none of us had went through the hardships like the one he had faced, even then he made it to the top overcoming all those baffling hurdles, thus setting himself as an example on how to conquer the unachievable, I believe theres a lot to learn from him for all of us.

I am quoting a striking sentence from the article, which really inspired me and certainly each one of you."

"You will accomplish 100% what you wish When you are firm in your goal."

You can find the complete article here. 



This is another story of a young man, whose had set an example of empowerment through education. You can find the complete article here.



Friday, April 16, 2010

Get yourself reviewed

Its the very instinct of every humanbeing to dream big and high, but what really makes one succeed is the moment when one assess himself/herself and starts to workout in a planned and focussed manner in materializing the dream.

Recently I came to stumble upon a site, that provided a cluster of assessment tests free of cost, if you are interested you can get yourself assessed at http://similarminds.com/, Click on "Personality Tests" link (located on the top left side of the image) and take a test of your choice.




Thursday, April 15, 2010

Google - Exploring the Hidden Jewels

Google the company that revolutionized the way people interact with internet, beginning all the way from search engine to its present offering the "Google OS". Its services had mostly been accepted with open arms by the internet community at large. 


As a Google user, i admire the way they innovate, transform ideas into successful solutions. I was keen to know what Google had under its sleeve other than the usual search we see. I was really taken away by the prowess they contained; If you had ever thought that Google is only meant to search the vast universe of internet data, then you might be blown away on what we are about to explore.


Google Calculator
The very simple input area on the Google search engine transforms itself to a scientific calculator, when you key in those mathematical equations and expressions. If you want to explore the Google Calc features to its brim, take a look here for a complete reference. I will list out some excerpts from the link






Google Expressions
I am listing out some expressions, which you can try out yourself
(Note: expressions are highlighted in bold. You can straight away enter those expressions to the Google search box.)




Percentage Expressions
12.3% of 344 - Gets 12.3 percentage of 344


Base Conversions
12 in binary - Gets the binary equivalent of 12
12 in octal - Gets the oct representation for 12
12 in hex - Gets the hex representation for 12
0b10 in decimal - Gets the decimal equivalent for the binary input of "0b10", for binary you must prefix "0b" (without quotes)
0o25 in decimal - Gets the decimal equivalent for the octal, for octal prefix "0o".
0x80 in decimal - Get decimal equivalent for hex, for hex prefix "0x".
20 degrees in radians - Converts degrees to radians.
10  radians in degrees - Converts radians to degrees.


Constants
3 pi - will output 3 * value of PI.


Simple Expressions
how many seconds in 1 hour
how many seconds in 5 weeks
how many seconds in 10 years
how many seconds in 10 centuries


how many days in a week
how many days in a year
how many days in a month
how many days in a century


speed of light
speed of sound




Volume\Date-Time Conversions
1 decade = ?year
1 millenium= ?year


1 km = ?meter
1 meter = ?km
1 furlong = ? meter
1 furlong = ? km



1 picometer = ?mm





1 yard = ? meter




1 mile = ?km


1 cm= ?km
1 cm= ?miles
1 cm = ?mm
1 nanometer = ?mm
1 feet = ?cm
1 decimeter = ? mm


1 volt = ? millivolts
1 joule  = ? watt hour
1 joule  = ? kilowatt hour
1 kilowatt hour = ? joule


1 ton = ? kg
1 ton = ? gram
1 kg = ? gram
1 pound  = ?kg
1 teaspoon = ? ml
1 cup = ? ml
1 gram  = ? kg
1 milligram  = ? gram
1 milligram  = ? kg
1 ounce  = ? kg
1 kg = ?lbs - reads 1 Kg is how many pounds
1 pound  = ? oz - reads to 1 pound is how many ounces








1 liter =?ml - 1 liter is how many milliliter
1 gallon  = ? liter
1 microliter  = ? liter
1 grain  = ? kg
1 cubic centimeter= ?ml
1 cubic centimeter= ?liter
1 cubic feet= ?liter
1 quart  = ?liter
1inch  = ?cm

1hz = ?khz


Currency Conversions
1 dollar = ? cent
1 USD = ? INR - Converts US Dollars to Indian Rupees
1 Euros in USD
1 USD in Euros


Google Language Translation - Expressions


en:fr Hello - Translates English to French
en:es Hello - Translates English to Spanish
en:it Hello - Translates English to Italian
en:de Hello - Translates English to German
en:zh Hello - Translates English to Chinese
en:ja Hello - Translates English to Japanese
en:ko Hello - Translates English to Korean
en:ru Hello - Translates English to Russian
en:en Avionics - Shows the pronunciation as well as the meaning of the word.




Misc Commands
define: Avionics - Shows up a list of definitions from different dictionaries and over from the web.


site:msdn.microsoft.com hooks - This will search only the msdn site for the term "hooks"


filetype:pdf C programming - This returns all PDF with the term "C Programming". You can replace the pdf with txt, doc, ppt, xls etc.




I will be updating this section with more new expressions and equations, so watch out for this space.








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.

Thursday, April 1, 2010

My First Blog Post

A hearty welcome to my personal blog "Tech Annotations". Its been a long cherished dream of mine to have a personal blog and finally the day had come to get transform my dream to reality. Starting with this post, I am really thrilled to be part of the blogosphere ecosystem, through my modest contributions, moreover i see this as an opportunity to give back to the community. 

Here you can find posts on Tech Innovations, Software Utilities, Code snippets, Puzzles  and what else!!! Oh Yes, my experiences with the IT Industry and then my other areas of interest like Science & Technology, Nature, Photography and definitely some humor stuff too.

I certainly hope you will benefit going through my blogs and I definitely welcome your valuable comments, suggestions and critics on my tidbits of posting in the days to come.
Thank you for you time and Thank You once again for visiting my blog. :)