如何将我的应用程序的快捷方式添加到Windows 7右键单击菜单 [英] How Can I Add My App's Shortcut To Windows 7 Right-click Menu
本文介绍了如何将我的应用程序的快捷方式添加到Windows 7右键单击菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将应用程序的快捷方式添加到Windows 7右键单击菜单
我尝试
How Can I Add My App''s Shortcut To Windows 7 Right-click Menu
i try
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(params string[] arguments)
{
if (arguments.Length > 0 && arguments[0] == "/launch")
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
AddMenu();
}
}
private const string MenuName = "Folder\\shell\\Launch";
private const string MenuValue = "Launch MyApp";
private const string Command = "Folder\\shell\\Launch\\command";
private const string AppPath = @"E:\Projects\C#4\WinTest\WinTest\bin\Debug\WinTest.exe /launch";
private static void AddMenu()
{
RegistryKey regmenu = null;
RegistryKey regcmd = null;
var registryPermission = new RegistryPermission(PermissionState.Unrestricted);
registryPermission.Assert();
try
{
regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
if (regmenu != null)
regmenu.SetValue("", MenuValue);
regcmd = Registry.ClassesRoot.CreateSubKey(Command);
if (regcmd != null)
regcmd.SetValue("", AppPath);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if (regmenu != null)
regmenu.Close();
if (regcmd != null)
regcmd.Close();
}
}
}
给出此错误
give this error
{"Access to the registry key ''HKEY_CLASSES_ROOT\\Folder\\shell\\Launch'' is denied."} <br />
System.Exception {System.UnauthorizedAccessException}<br />
感谢您的帮助
thanks for any help
推荐答案
以管理员身份安装上下文菜单项或将注册表项更改为:
HKEY_CURRENT_USER\Software\Classes
根据cmdHere的指南:
http://www.commandline.co.uk/cmdhere/index.html
Install the context menu item as an administrator or change the registry key to:
HKEY_CURRENT_USER\Software\Classes
as per the guide for cmdHere:
http://www.commandline.co.uk/cmdhere/index.html
这篇关于如何将我的应用程序的快捷方式添加到Windows 7右键单击菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文