C # Read and write registry

Source: Internet
Author: User
Tags modify reference win32
Registry C # Programming to create your own IE browser Choose from Yudehui Blog
Keyword C # programming to build your own IE browser
Source

Disclaimer: This article has been put on the Tenkine station, this is just a collection. Not to reprint without permission

IE is now the Windows platform to use the most browser, then how to use the program to modify IE, to create their own characteristics of IE?

I'm here to introduce how C # uses the registry to modify IE.

First, let's familiarize ourselves with the method and function of modifying the registry in C #. The registry class, RegistryKey class is provided in vc# to implement the operation of the registry. The Registry class encapsulates seven basic keys for the registry:

Registry.classesroot corresponds to the HKEY_CLASSES_ROOT primary key
Registry.currentuser corresponds to the HKEY_CURRENT_USER primary key
Registry.localmachine corresponds to the HKEY_LOCAL_MACHINE PRIMARY key
Registry.user corresponds to the Hkey_user primary key
Registry.currentconfig corresponds to the Heky_current_config primary key
Registry.dynda corresponds to the Hkey_dyn_data primary key
Registry.PerformanceData corresponds to the Hkey_performance_data primary key

The RegistryKey class encapsulates basic operations on the registry, including read, write, and delete. The main functions read are:

The OpenSubKey (string name) method primarily opens the specified subkey.
The Getsubkeynames () method is to obtain the name of all subkeys below the primary key, and its return value is an array of strings.
The GetValueNames () method is to get all the key names in the current subkey, and its return value is also an array of strings.
The GetValue (string name) method is the key value of the specified key.

The functions that are written are:

The CreateSubKey (string name) method is to add a subkey

The SetValue (string name,string value) method is to set the key value of a key



Deleted functions:

DeleteSubKey () Method: Deletes a specified subkey.

Deletesubkeytree () Method:

This method is to completely delete the specified subkey directory, that is, delete the subkey and all subkeys below the subkey.

Through the registry can modify IE, here I briefly introduce a few commonly used to achieve the changes to IE.

If we want the window that is open to be animated when you turn on or off the IE window, you can open the Hkey_ current_user \ Control panel\ desktop\ windowmetrics key and create a new string in the right window. Minanimat "and" Maxanimat "and set the value of" 0 "for" 1 ", so that the maximum of IE window to minimize the transition effect.

If we change to IE toolbar to add a background then expand HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\toolbar key value, the Explorer primary key under the new one named " Backbitmap, and modifies its value to the full path and filename of the prepared BMP picture, so that we have completed the purpose of adding a background image for IE's toolbar.

The following methods are implemented in C # programming:

1.IE window's dynamic effect

//-------------------------------------

changeie.cs©2004 by Yudehui

//-------------------------------------

Using System;

Using Microsoft.Win32; Be sure to reference this namespace for registry operations

Namespace Changeie

{

Class Changeie

{

[STAThread]

static void Main (string[] args)

{

RegistryKey Pregkey;

Pregkey = Registry.CurrentUser.OpenSubKey ("Control Panel\\desktop\\windowmetrics", true);

if (pregkey==null)

{

Console.WriteLine ("Key value does not exist");

}

Else

{

Pregkey. SetValue ("MinAnimate", "1");

Pregkey. SetValue ("Maxanimate", "1");

Console.WriteLine ("Successful modification");



}

Pregkey. Close;

}

}

}

2. Change the background of IE toolbar

//-------------------------------------

changeie.cs©2004 by Yudehui

//-------------------------------------

Using System;

Using Microsoft.Win32; Be sure to reference this namespace for registry operations

Namespace Changeiebackcolor

{

Class Changeiebackcolor

{

[STAThread]

static void Main (string[] args)

{

RegistryKey Pregkey;

Pregkey = Registry.CurrentUser.OpenSubKey ("software\\microsoft\\internet" +

"Explorer\\toolbar\\explorer", true);

if (pregkey==null)

{

Console.WriteLine ("Key value does not exist");

}

Else

{

Pregkey. SetValue ("Backbitmap", "c:\\windows\\greenstone.bmp");

Console.WriteLine ("Successful modification");



}

Pregkey. Close;

}

}

}

The above two simple examples are only the simple setting of IE, I believe that we have a certain understanding of the operation of the Registry under C #. Interested readers can make more personalized changes to IE, the above code under the Windows2003+vs.net2003 debugging pass.

Note: The operation of the Registry is a certain risk, the operation should be backed up to prevent misoperation, and lead to system crashes.




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.