Wednesday, 21 March 2012

How to add an application to windows Context Shell?




Windows context shell is the menu which appears when you right click on any file. It provides you a list of operations that can be performed on that file. But how it works? How to add your own program in this context shell? As you go further you will find the answers of these questions.

Before going ahead one should know about windows registry. It is a kind of journal that the windows OS maintains to track its various activities such as file associations, context shell, users and its privileges etc.

How to add a program in windows context shell?
  1. Open registry editor by typing ‘regedit’ in ‘Run’ command. 
  2. Once the editor is open go to HKEY_CLASSES_ROOT -> * -> Shell 
  3. Then right click to create a new key. Give the name that you want to be appeared in context shell. You can view the image for clear understanding. 
  4. Then create a sub key with name "command" and edit its value to the "path of your program" as shown in the image. And the job is done. 
  5. Now right click on any file and you can see that your app  is appearing in the context shell.
How to make it work with your app?

  1. To make your application working with this context shell, you should know how to work with command line arguments. It doesn’t matter whether you are using C,C++, C# or java. 
  2. I have written a sample C program,  which displays the name and the whole path of the file which have been selected through the context shell. 
  3. Here’s the code :
#include<stdio.h>
#include<conio.h>
void main(int argc, char *argv[])
{
  if(argc!=0)
  {
    printf("\nThe file you just clicked is\n\n");
    printf("%s",argv[1]);
  }
getch();
}

The image shows the output of this program.

Similarly you can associate numerous files with your application using windows context shell and basic command line arguments.



No comments:

Post a Comment

 
Host Unlimited Websites. Starting @ Rs.59