I'm going to show you how to read registry.
The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components as well as the applications running on the platform: the kernel, device drivers, services, SAM, user interface and third party applications all make use of the Registry. The registry also provides a means to access counters for profiling system performance.
For instance, we are making a program for a game. We don't want the user to set his install directory, we want to get it with vb.net. Let's take a specific example. I want to do a modern warfare 2 trainer and I'm trying to get the install path.
Microsoft.Win32 has a built in feature to read registry.
First off all, to go into the registry, do the following:
Start > Run > "RegEdit"
Hit ok.
Welcome to the Registry
It looks like this:
We are going to work with "HKEY_LOCAL_Machine" because installed program paths and other information are stored here.
Abbreviated HKLM, HKEY_LOCAL_MACHINE stores settings that are specific to the local computer. On NT-based versions of Windows, HKLM contains four subkeys, SAM, SECURITY, SOFTWARE and SYSTEM, that are found within their respective files located in the %SystemRoot%\System32\config folder. A fifth subkey, HARDWARE, is volatile and is created dynamically, and as such is not stored in a file. Information about system hardware drivers and services are located under the SYSTEM subkey, while the SOFTWARE subkey contains software and Windows settings.
Let us try to find Modern Warfare 2 by using Control + F.
Yay we've successfully found it =D
Now you actually see something called "InstallPath" as value it has the install directory, for instance: "C:\Program Files\Steam\SteamApps\common\call of duty modern warfare 2".
Let's go into VB.
Start a new project.
Hit ok.
Drag a button on the form.
Doubleclick on the button.
Now, to read the registry you have to use the following path.
Code:
Try
Dim currhive As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim branch As Microsoft.Win32.RegistryKey = currhive.OpenSubKey("Software\Activision\Modern Warfare 2", False)
Dim value As String = CType(branch.GetValue("InstallPath"), String)
branch.Close()
MsgBox(value)
Catch
MsgBox(ErrorToString)
End Try
It'll look like this:
Code:
Try
Catch
Msgbox(errortostring)
end try
This is used for error-catching. If an error appears, it will catch it and use a message box to visualize it. Else, if an error appears, the program will just close.
Code:
Dim branch As Microsoft.Win32.RegistryKey = currhive.OpenSubKey("Software\Activision\Modern Warfare 2", False)
This is pretty self-explaining.
,False = writeable
If you are into changing the value, set it to True.
Code:
Dim value As String = CType(branch.GetValue("InstallPath"), String)
To test it simply debug it by hitting "F5".
I do hope you did understand everything.
This tutorial is NOT leeched, just written it a second ago
Enjoy!