C # customization file icon Double-click Start (Modify registry)

Source: Internet
Author: User

Custom files generated by the program, such as the suffix. Test

How does this file start to open the program directly and open the file?

1. Double-click to open

2. custom files with icon display

3. Customize the file, right click to have the corresponding property

Background code: (How to modify information in the registry)

    //Tool Startup Path    stringToolpath = System.Windows.Forms.Application.StartupPath +"\ \ Mail gadget. exe"; stringExtension =sptdconst.fileextension; stringFileType ="Email File"; stringFilecontent ="Text/plain"; //Get informationMicrosoft.Win32.RegistryKey RegistryKey =Microsoft.Win32.Registry.ClassesRoot.OpenSubKey (extension); if(RegistryKey! =NULL&& Registrykey.opensubkey ("Shell") !=NULL&& Registrykey.opensubkey ("Shell"). OpenSubKey ("Open") !=NULL&&Registrykey.opensubkey ("Shell"). OpenSubKey ("Open"). OpenSubKey ("Command") !=NULL)    {        varVarsub = Registrykey.opensubkey ("Shell"). OpenSubKey ("Open"). OpenSubKey ("Command"); varVarvalue = Varsub.getvalue (""); if(Object.Equals (varvalue, Toolpath +"%1"))        {            return; }    }    //DeleteMicrosoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree (Extension,false); //File RegistrationRegistryKey =Microsoft.Win32.Registry.ClassesRoot.CreateSubKey (extension); RegistryKey.SetValue ("File Type", FileType); RegistryKey.SetValue ("Content Type", filecontent); //Set default iconMicrosoft.Win32.RegistryKey Iconkey = Registrykey.createsubkey ("DefaultIcon"); Iconkey.setvalue ("", System.Windows.Forms.Application.StartupPath +"\\logo.ico"); //Set default open program pathRegistryKey = Registrykey.createsubkey ("Shell\\open\\command"); RegistryKey.SetValue ("", Toolpath +"%1"); //CloseRegistrykey.close ();

After you have modified the registry information, double-click the file to start the software, and then how to operate in the code?

 // If a space exists in the original path, it will be decomposed into multiple elements if0) {      string  FilePath = String.Join ("", E.args.toarray ());       New FileInfo (FilePath);       if (file. Exists)       {           = file. FullName;       }  }

You can then determine whether the Doubleclicksptdfilepath has a value in the main program loaded method, and if so, get the file under the path and proceed.

C # customization file icon Double-click Start (Modify registry)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.