C# Shell上下文菜单
我目前正在运行一台C# Shell上下文菜单,c#,contextmenu,windows-shell,C#,Contextmenu,Windows Shell,我目前正在运行一台Windows7x64计算机 我编写了以下代码,以便在右键单击时添加上下文菜单: RegistryKey rKey = Registry.ClassesRoot.OpenSubKey("Directory\\Background\\shell", true); String[] names = rKey.GetSubKeyNames(); foreach (String s in names) { System.Windows.F
Windows7x64计算机
我编写了以下代码,以便在右键单击时添加上下文菜单:
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();
如果我直接在注册表上重复这个过程,它会工作,但不是通过这个
我还可以访问注册表,因为我添加了一个代码段,其中列出了我需要的所有子项,但没有添加任何子项。我已经测试了您的代码,它很好。看起来您没有从代码中打开注册表的访问权限。只需遵循以下简单步骤:
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">
我已经测试了你的代码,它很好。看起来您没有从代码中打开注册表的访问权限。只需遵循以下简单步骤:
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">
谢谢,成功了。比如说,我将其绑定到一个
.exe
,让用户在他们的系统上创建类似的菜单。我怎样才能“以管理员身份运行”呢?谢谢,这很有效。比如说,我将其绑定到一个.exe
,让用户在他们的系统上创建类似的菜单。我如何能够动态“以管理员身份运行”?
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>