introduction this code will help u to add your application to windows context menu of selected file.
namespaces used namespace used for this is Microsoft.Win32 which is imported using
using Microsoft.Win32;
Description and Code
to add your application to windows context menu of selected file , you only need to create one registry key in HKEY_CLASSES_ROOT\*\Shell with the user defined name and one in this newly created key with name command which is pointing to your application. This is done your application is now added to windows context menu and when you click on thi your application will get started. and to create registry key you will need to call SetValue method of Registry Class. here is the code :
Registry.SetValue(@"HKEY_CLASSES_ROOT\*\Shell\myapp2", "", "myapp2", RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\*\Shell\myapp2\Command", "", "notepad.exe", RegistryValueKind.String);
here second parameter is an empty string because we want to set default value of the key created. 3rd parameter in first line (i.e, myapp2) is the name that you want to display in the context menu. 3rd parameter in second line (i.e. "notepad.exe" ) is the application exe name that you want to open on clicking the option in context menu . if you want the selected file should open in the application then this parameter will be "notepad.exe %1" attaching %1 with the application name will pass the file name to be opened on starting the application.
Attachments
|
| Author: Abhishek Arya 23 May 2008 | Member Level: Diamond Points : 2 |
good one
|
| Author: mani kumar.k.m 24 May 2008 | Member Level: Gold Points : 2 |
Hi,
this code snippets usefull to me. nice example.
thanks
|