修改註冊表,雙擊文件直接打開 string strProject = "Exec"; string p_FileTypeName =".cdb";//文件尾碼 string fileName = System.Windows.Forms.Application.ExecutablePath;// 獲 ...
修改註冊表,雙擊文件直接打開
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); }