Thursday, March 08, 2007

* Creating a context menu item for folders

I remember in .NET 1.0 sdk there used be a sample which demonstrated how to modify registry through CSharp. By doing so it used to add an item into the context menu of folders in windows explorer. The best thing about that item was that it can be used to open a command window directly into that folder which is very useful if you work with lot of console applications.

Well, i couldn't find it in .NET 3.0 sdk samples but managed to find how to write such a sample.

Here is the code which is very simple and demonstrate the power of CSharp.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace RegistryProgram
{
class Program
{
static void Main(string[] args)
{
try
{
Registry.ClassesRoot.CreateSubKey("Directory\\shell\\CmdWindow");
RegistryKey rk = Registry.ClassesRoot.CreateSubKey("Directory\\shell\\CmdWindow\\command");
rk.SetValue("","cmd \"%1\"");

}
catch(System.Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
}






~tata & take care~



Other Posts



No comments:

Post a Comment