C # Registry Programming Example two: Add your own file type in new

Source: Internet
Author: User

The following example adds your own file type in the right-click shortcut menu on the desktop or in new in Windows Explorer. Suppose you add a file with the extension ". cs", the file is "CS files," and the default file opens with WordPad notepad.exe in Windows.

Program Listing 18-2:

Using System;
Using Microsoft.Win32;
Class Regtest
{public
 static void Main ()
 {
  RegistryKey key1=registry.classesroot.createsubkey (". CS ");
  Key1. SetValue ("", "CS");
  RegistryKey Key2=key1. CreateSubKey ("Shellnew");
  Key2. SetValue ("Nullfile", "");
  Key1. Close ();
  Key2. Close ();
  Key1=registry.classesroot.createsubkey ("CS");
  Key1. SetValue ("", "CSharp file");
  Key2. SetValue ("", "c:\\windows\\notepad.exe,1");
  Key2. Close ();
  Key2=key1. CreateSubKey ("Shell\\open\\command");
  Key2. SetValue ("", "C:\\windows\\notepad.exe");
  }

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.