日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

C# 右键菜单注册表改写

發布時間:2024/3/12 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# 右键菜单注册表改写 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.改寫注冊表,并將工程屬性改成以管理員身份運行。具體方式:在工程的properties上右擊,打開,點擊屬性窗口左側的“安全性”,勾選右側的“啟動ClickOnce安全設置”,就會在Properties目錄下出現app.manifest文件,將里面的“”改成“ ”。再將“啟動ClickOnce安全設置”上的勾選去掉,即可。此時,生成的exe上會出現一個以管理員身份運行的圖標,雙擊exe將自動以管理員身份運行。
這樣做右擊一個文件,是能用自己的應用程序打開該文件的,但出現右擊多個exe,就會出現問題。
private bool RegisterRightMenu()
{
try
{
RegistryKey shellKey = Registry.ClassesRoot.OpenSubKey(@”*\shell”,
RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
if (shellKey == null)
shellKey = Registry.ClassesRoot.CreateSubKey(@”*\shell”);
//創建項:右鍵顯示的菜單名稱
RegistryKey rightCommondKey = shellKey.CreateSubKey(“資源拷貝工具(” + Application.ProductVersion + “)”);
RegistryKey associatedProgramKey = rightCommondKey.CreateSubKey(“command”);

//創建默認值:關聯的程序//associatedProgramKey.SetValue(string.Empty, Process.GetCurrentProcess().MainModule.FileName + " %1");associatedProgramKey.SetValue(string.Empty, Process.GetCurrentProcess().MainModule.FileName + " %1");//associatedProgramKey.SetValue(string.Empty, @"F:\engeneer\x51_8796\exe\資源拷貝工具\ResCopyTool.exe %1");//刷新到磁盤并釋放資源associatedProgramKey.Close();rightCommondKey.Close();shellKey.Close();RegistryKey shellKey1 = Registry.ClassesRoot.OpenSubKey(@"directory\shell",RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);if (shellKey1 == null)shellKey1 = Registry.ClassesRoot.CreateSubKey(@"directory\shell");//創建項:右鍵顯示的菜單名稱RegistryKey rightCommondKey1 = shellKey1.CreateSubKey("資源拷貝工具(" + Application.ProductVersion + ")");RegistryKey associatedProgramKey1 = rightCommondKey1.CreateSubKey("command");//創建默認值:關聯的程序associatedProgramKey1.SetValue(string.Empty, Process.GetCurrentProcess().MainModule.FileName + " %1");//刷新到磁盤并釋放資源associatedProgramKey1.Close();rightCommondKey1.Close();shellKey1.Close();return true;}catch (Exception e){Outputs.WriteLine(OutputMessageType.Error, "設置右鍵菜單失敗:" + e.Message);return false;}}private bool UnRegisterRightMenu(){try{RegistryKey shellKey = Registry.ClassesRoot.OpenSubKey(@"*\shell",RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);if (shellKey == null)shellKey = Registry.ClassesRoot.CreateSubKey(@"*\shell");shellKey.DeleteSubKey("資源拷貝工具(" + Application.ProductVersion + ")\\command");shellKey.DeleteSubKey("資源拷貝工具(" + Application.ProductVersion + ")");//刷新到磁盤并釋放資源shellKey.Close();RegistryKey shellKey1 = Registry.ClassesRoot.OpenSubKey(@"directory\shell",RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);if (shellKey1 == null)shellKey1 = Registry.ClassesRoot.CreateSubKey(@"directory\shell");shellKey1.DeleteSubKey("資源拷貝工具(" + Application.ProductVersion + ")\\command");shellKey1.DeleteSubKey("資源拷貝工具(" + Application.ProductVersion + ")");shellKey1.Close();return true;}catch (Exception e){Outputs.WriteLine(OutputMessageType.Error, "設置右鍵菜單失敗:" + e.Message);return false;}}

2.查詢右鍵菜單是否有這一項,通過查詢注冊表:
private bool GetIsAddRightMenu()
{
RegistryKey shellKey = Registry.ClassesRoot.OpenSubKey(@”*\shellex”,
RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.ReadKey);
if (shellKey == null)
return false;
else
{
RegistryKey rightMenuKey = shellKey.OpenSubKey(“ContextMenuHandlers”);
if (rightMenuKey == null)
{
return false;
}
else
{
RegistryKey resCopyToolKey = rightMenuKey.OpenSubKey(“ResCopyToolExtension”);
if (resCopyToolKey == null)
{
return false;
}
else
{
resCopyToolKey.Close();
}
rightMenuKey.Close();
}
shellKey.Close();
}
return true;
}
3.另一種修改右鍵菜單的方法:

總結

以上是生活随笔為你收集整理的C# 右键菜单注册表改写的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。