修改注冊表,雙擊檔案直接打開
string strProject = "Exec"; string p_FileTypeName =".cdb";//檔案后綴 string fileName = System.Windows.Forms.Application.ExecutablePath;// 獲取啟動了應用程式的可執行檔案的路徑及檔案名 //string startPath = System.Windows.Forms.Application.StartupPath;//獲取啟動了應用程式的可執行檔案的路徑 //注冊檔案型別
Registry.ClassesRoot.CreateSubKey(p_FileTypeName).SetValue("", strProject, RegistryValueKind.String); using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(strProject)) { //設定圖示 RegistryKey iconKey = key.CreateSubKey("DefaultIcon"); iconKey.SetValue("", System.Windows.Forms.Application.StartupPath + "\\ooopic_1564036072.ico"); //設定默認啟動程式 key.CreateSubKey(@"Shell\Open\Command").SetValue("", fileName + " \"%1\"", RegistryValueKind.ExpandString); }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/67169.html
標籤:C#
下一篇:C#中實作檔案拖放打開的方法
