Automated Testing reads and writes the 64-bit operating system registry, read and write 64-bit

Source: Internet
Author: User

Automated Testing reads and writes the 64-bit operating system registry, read and write 64-bit

Non-Web programs (desktop programs) are usually set in the registry. When performing automated tests on these programs, you need to deal with the Registry frequently. Modify the settings of a program by modifying the registry.

This chapter describes how to use the C # program to operate the registry, especially the 64-bit operating system registry.

Reading directory

  1. You often need to modify the registry for automated testing.
  2. Windows Registry Overview
  3. C # modify the Registry
  4. Differences between a 32-bit machine and a 64-bit machine Registry
  5. C # access the registry of a 64-bit Operating System

You often need to modify the registry for automated testing.

Many system settings (such as IE settings) exist in the registry. The settings of the desktop application are also in the registry. Therefore, when performing automated testing, you often need to modify the registry.

Windows Registry Overview

The Registry Editor is in C: \ Windows \ regedit.exe. Or you can start the Registry Editor by running "regedit.

The Registry consists of primary Keys, keys, subkeys, and value items. For example

The content of HKEY_CURRENT_USER in the primary key is similar to that in HKEY_LOCAL_MACHINE. One is the setting of the current user and the other is the setting of the machine.

 

C # modify the Registry

C # it's too easy to modify the Registry. Add using Microsoft first. win32; just a few lines of code. You can read, add, delete, modify, and operate the following instances.

Static void Main (string [] args) {// instance, modify the IE homepage RegistryKey localMachine = Registry. currentUser; RegistryKey sougou = localMachine. openSubKey (@ "SOFTWARE \ Microsoft \ Internet Explorer \ MAIN", true); // obtain the IE homepage string version = sougou. getValue ("Start Page "). toString (); // modify the IE homepage sougou. setValue ("Start Page", "http://www.cnblogs.com/", RegistryValueKind. string); // modify the value of Tanktest. If it does not exist, create a new value of TankTest. Sougou. setValue ("TankTest2", "1", RegistryValueKind. DWord); // Delete the value item sougou. deleteValue ("TankTest2"); // create a subkey sougou. createSubKey ("This is subkey1"); sougou. createSubKey ("This is subkey2"); // Delete the subkey sougou. deleteSubKey ("This is subkey1 ");}

Differences between a 32-bit operating system and a 64-bit operating system registry

The above code runs on a 32-bit operating system, but it does not work in a 64-bit operating system.

Application software can also be divided into 32-bit and 64-bit. In a 64-bit operating system, you can run 32-bit applications and 64-bit applications.

If a 32-bit application is installed in a 64-bit operating system, it is installed under C: \ Program Files (x86. Start the task manager, and you will see the 32-bit program process name with a "* 32", such:

Note: In a 64-bit operating system:

The 64-bit program's registry is still in: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Internet Explorer

The 32-bit program's registry is in: HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Internet Explorer

C # access the registry of a 64-bit Operating System

C # programs are all 32-bit. when accessing the registry, they will access HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \, but cannot access HKEY_LOCAL_MACHINE \ SOFTWARE \

Before. NET 3.5, the C # program must use the Win32API function (several hundred lines of code are required) to access the registry of the 64-bit operating system.

. NET 4.0 and later access the 64-bit operating system registry is very simple.

Static void Main (string [] args) {// modify the registry of the 64-bit operating system // modify the IE homepage // use RegistryView to specify whether it is a 64-bit operating system or a 32-bit RegistryKey localKey = RegistryKey. openBaseKey (Microsoft. win32.RegistryHive. currentUser, RegistryView. registry64); localKey = localKey. openSubKey (@ "SOFTWARE \ Microsoft \ Internet Explorer \ Main", true); if (localKey! = Null) {localKey. SetValue ("Start Page", "http://www.cnblogs.com ");}}

The above is the information for reading and writing the registry of the 64-bit operating system through automated testing. We will continue to sort out relevant information in the future. Thank you for your support for this site!

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.