C#設置自定義文件圖標實現雙擊啟動


修改注冊表,雙擊文件直接打開

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); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM