C # Development notes for small software (SaveClassic) -- (3) Basic Class (registry operation class RegEdit)

Source: Internet
Author: User

 

This class mainly implements the modification of the Registry, and the code is also in the vernacular, which is very simple and will be used in form development. The Code is as follows.

1 using Microsoft. Win32;

2 namespace Common

3 {

4 public class RegEdit

5 {

6 public RegEdit ()

7 {

8}

9 // obtain data in the Registry

10 public string GetRegistData (string name)

11 {

12 string registData;

13 RegistryKey hkml = Registry. LocalMachine;

14 RegistryKey software = hkml. OpenSubKey ("SOFTWARE", true );

15 RegistryKey aimdir = software. OpenSubKey ("Microsoft", true );

16 registData = aimdir. GetValue (name). ToString ();

17 return registData;

18}

19 // write the registry data www.2cto.com

20 public void WTRegedit (string name, string tovalue)

21 {

22 RegistryKey hklm = Registry. LocalMachine;

23 RegistryKey software = hklm. OpenSubKey ("SOFTWARE", true );

24 RegistryKey aimdir = software. CreateSubKey ("XXX ");

25 aimdir. SetValue (name, tovalue );

26}

27 // Delete registry data

28 public void DeleteRegist (string name)

29 {

30 string [] aimnames;

31 RegistryKey hkml = Registry. LocalMachine;

32 RegistryKey software = hkml. OpenSubKey ("SOFTWARE", true );

33 RegistryKey aimdir = software. OpenSubKey ("XXX", true );

34 aimnames = aimdir. GetSubKeyNames ();

35 foreach (string aimKey in aimnames)

36 {

37 if (aimKey = name)

38 aimdir. DeleteSubKeyTree (name );

39}

40}

41

42 // determine whether the data in the registry exists

43 public bool IsRegeditExit (string name)

44 {

45 bool _ exit = false;

46 string [] subkeyNames;

47 RegistryKey hkml = Registry. LocalMachine;

48 RegistryKey software = hkml. OpenSubKey ("SOFTWARE", true );

49 RegistryKey aimdir = software. OpenSubKey ("Microsoft", true );

50 subkeyNames = aimdir. GetSubKeyNames ();

51 foreach (string keyName in subkeyNames)

52 {

53 if (keyName = name)

54 {

55 _ exit = true;

56 return _ exit;

57}

58}

59 return _ exit;

60}

61}

62}

Author zhaoyang

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.