Home >Computer Tutorials >Computer Knowledge >Local registry pointing tool under winpe

Local registry pointing tool under winpe

WBOY
WBOYforward
2024-02-09 15:20:391006browse

php editor Banana introduces you a practical tool - the local registry pointing tool under WinPE. In the WinPE system, since there is no ability to directly access the local registry, we cannot modify or query the registry information. This tool provides a simple and effective solution that can point the WinPE system's registry to the local system, allowing us to easily operate the registry. Whether it is fixing system problems or performing system maintenance, this tool can help us save time and energy.

The location where this information is recorded in the registry is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

Therefore, as long as we can access the registry At this location, you can get the name and installation path information of some software.

This blog post uses C# to access the registry to obtain the software installation path and display it.

1 Description of the main screen of the sample program

The main screen of the sample program is as shown below.

Local registry pointing tool under winpe

Enter the name of the executable program in the text box on the screen, and then click the "Get Path" button. Next, the next line of the screen will display the complete installation path information of the program. Note that the executable name you enter must be the name of the program in the registry. For example, the name of Adobe Reader in the registry is "AcroRd32.exe".

2 Complete code of sample program

using System;

using System.Windows.Forms;

using Microsoft.Win32;

namespace GetSoftWarePathExp

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

try

{

string softName = textBox1.Text.ToString();

string strKeyName = string.Empty;

string softPath = @\"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\\";

RegistryKey regKey = Registry.LocalMachine;

RegistryKey regSubKey = regKey.OpenSubKey(softPath softName \".exe\", false);

object objResult = regSubKey.GetValue(strKeyName);

RegistryValueKind regValueKind = regSubKey.GetValueKind(strKeyName);

if (regValueKind == Microsoft.Win32.RegistryValueKind.String)

{

this.label3.Text = objResult.ToString();

}

}

catch

{

this.label3.Text = \"Friend, failed to obtain the program path!\";

}

}

}

}

Note: Need to add reference: using Microsoft.Win32;

3 Code Description

(1) The code "RegistryKey regKey = Registry.LocalMachine" makes regKey point to the registry primary key HKEY_LOCAL_MACHINE .

(2) The code "RegistryKey regSubKey = regKey.OpenSubKey(softPath softName \".exe\", false)" makes regSubKey point to the registry subkey we need to find.

(3) The code "object objResult = regSubKey.GetValue(strKeyName)" obtains the key value of the registry.

(4) Code "RegistryValueKind regValueKind = regSubKey.GetValueKind(strKeyName)" obtains the key value type of the registry.

(5) Finally output the obtained key value information.

(6) If there is an error in the program, the prompt message "Friend, failed to obtain the program path!" will be output.

Note: Both the RegistryKey.GetValue and RegistryKey.GetValueKind methods need to pass in a parameter to indicate the name of the value to be retrieved. When the parameter passed to the RegistryKey.GetValue and RegistryKey.GetValueKind methods is an empty string, What is retrieved is an unnamed value. When this unnamed value is displayed in the Registry Editor, the string "(Default)" will be displayed instead of displaying a name. In this example, an empty string is passed in. If we take the installation information of the software Adobe Reader as an example, we will get the first registry information in the figure below. At this time, the name item displays the string "( default)".

Local registry pointing tool under winpe

4 Program running results

(1) Get the installation path of Adobe Reader

Enter "AcroRd32", click "Get Path", and get the following results, yes It is not consistent with the information recorded in the registry.

Local registry pointing tool under winpe

2) Get the installation path of chrome

Enter "chrome", click "Get Path", and you will get the following results. Is it consistent with the information recorded in the registry?

Local registry pointing tool under winpe

5 A few more words

In development, sometimes a specific program is designated to perform a certain type of operation, which may involve reading registry information to open the program. It's just that some programs may not have such registration information. In this case, we must take other methods.


The above is the detailed content of Local registry pointing tool under winpe. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:pc-daily.com. If there is any infringement, please contact admin@php.cn delete