use*_*912 0 c# contextmenu windows-shell
我目前正在运行Windows 7 x64 machine.
我编写了以下代码来右键单击添加上下文菜单:
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();
Run Code Online (Sandbox Code Playgroud)
如果我直接在注册表上重复该过程,它可以工作,但不是通过这个.
我也能够访问注册表,因为我添加了一个片段,告诉列出我需要的所有子键,但根本不添加一个.
我已经测试了你的代码,它非常好.看起来你没有从代码中打开注册表的访问权限.只需按照以下简单步骤:
如果要直接从Exe运行程序,请右键单击Exe并选择Run As Administrator选项.
如果您不想以管理员身份运行,请按照下列步骤操作:
只需用MyApplication.app替换您的应用程序名称即可.重要的部分是该部分.休息是自动生成的.
Run Code Online (Sandbox Code Playgroud)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>
| 归档时间: |
|
| 查看次数: |
781 次 |
| 最近记录: |