Automated test Read and write 64-bit operating system Registry _ Basics

Source: Internet
Author: User
Tags win32

Settings for non-web programs (desktop programs) generally exist in the registry. When automating tests on these programs, you need to deal with the registry frequently. Modify the settings of your program by modifying the registry.

This chapter describes how to manipulate the registry with C # programs, especially how to operate a 64-bit operating system registry.

Reading Table of Contents

    1. Automated tests often need to modify the registry
    2. Introduction to Windows Registry
    3. C # Modify Registry
    4. Difference between a 32-bit machine and a 64-bit machine registry
    5. C # programs access the registry of a 64-bit operating system

Automated tests often need to modify the registry

Many system settings, such as IE settings, are present in the registry. The settings for the desktop application also exist in the registry. So when you do automated testing, you often need to modify the registry

Introduction to Windows Registry

Registry Editor in C:\Windows\regedit.exe. Or, run "regedit" in operation. You can start Registry Editor.

The registry consists of a primary key, a key, a subkey, and a value entry. The following figure

In the primary key: HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE are similar in content, one is the current user's settings, one is the machine settings.

C # Modify Registry

C # To modify the registry is too simple, first add using Microsoft.Win32; A few lines of code are done, look at the example below, read, add, delete, change, the operation has.

static void Main (string[] args)
  {
   //instance, modify IE homepage
   registrykey localmachine = registry.currentuser;
   RegistryKey Sougou = Localmachine.opensubkey (@ "Software\Microsoft\Internet Explorer\Main", true);
   Get IE's homepage
   string version = Sougou. GetValue ("Start Page"). ToString ();
   Modify IE's homepage 
   Sougou. SetValue ("Start Page", "http://www.cnblogs.com/", registryvaluekind.string);

   Modify Tanktest This value entry, if it does not exist, create a new Tanktest value entry.
   Sougou. SetValue ("TankTest2", "1", Registryvaluekind.dword);
   Deletes a value entry
   Sougou. DeleteValue ("TankTest2");
   
   New subkey
   Sougou. CreateSubKey ("This is Subkey1");
   Sougou. CreateSubKey ("This is Subkey2");
   
   Delete subkey
   Sougou. DeleteSubKey ("This is Subkey1");
  }

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

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

The application software also has 32-bit and 64-bit points. In a 64-bit operating system, you can run 32-bit applications and 64-bit applications.

If you install a 32-bit application in a 64-bit operating system, it is installed to the C:\Program Files (x86) \. When you start Task Manager, you will see the 32-bit program's process name followed by a "*32", as shown below:

Note: In 64-bit operating systems:

The registry for 64-bit programs is still in: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer

32-bit program registry but in: Hkey_local_machine\software\wow6432node\microsoft\internet Explorer

C # programs access the registry of a 64-bit operating system

C # 's programs are 32-bit, access to the registry, access to Hkey_local_machine\software\wow6432node\, and access to hkey_local_machine\software\

. NET 3.5 A C # program needs to access the registry of a 64-bit operating system by using the WIN32API function (hundreds of lines of code to write).

The Registry of the 64-bit operating system after. NET 4.0 is simple.

static void Main (string[] args)
  {
   //Modify the 64-bit operating system registry
   //Modify IE's homepage//
   by Registryview to specify whether 64-bit operating system or 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 automated test read and write 64-bit operating system registry information, follow-up to continue to collate relevant information, thank you for your support of 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.