c# - Shell Context Menus -
i running windows 7 x64 machine
.
i have written following code add context menu on right click:
registrykey rkey = registry.classesroot.opensubkey("directory\\background\\shell", true); string[] names = rkey.getsubkeynames(); foreach (string s in names) { system.windows.forms.messagebox.show(s); } registrykey newkey = rkey.createsubkey("your application"); registrykey newsubkey = newkey.createsubkey("command"); newsubkey.setvalue("", "c:\\windows\\system32\\notepad.exe"); newsubkey.close(); newkey.close(); rkey.close();
if repeat procedure directly on registry, works, not via this.
i able access registry, have added snippet tells lists subkeys require, not add one.
i have tested code , & good. looks dont have access rights open registry code. follow these simple steps:
- close visual studio. open again run administrator mode. 1 can right clicking on visual studio link , choose run administrator option.
- open code , run there.
if want directly run program exe right click on exe & choose run administrator option.
if don't want run administrator, follow these steps:
- add new file project called app.manifest; adding new file project.
- add following data file, rest magic.
just replace application name myapplication.app. important part section. rest auto generated.
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <assemblyidentity version="1.0.0.0" name="myapplication.app" /> <trustinfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedprivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedexecutionlevel level="requireadministrator" uiaccess="false" /> </requestedprivileges> </security> </trustinfo> </asmv1:assembly>