Jump to content

HELLP!! Creating Regisrty keys in LocalMachine Using Visual Basic

AgentEddie99

Hi forums,

 

I need some help creating some registry keys in the local machine folder in the registry using the coding language of Visual basic (I know is an old language, but I need to start somewhere). I'm trying to create a key that says "Model" in the OEM Information folder and set the value of that to "Gaming PC" for example. Below is the location of where I want the key to go, the main issue is that the permissions with writing to the local machine because the localmachine is the computer. I would like someone to help me get around the permissions issue.

 

KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation

 

Hope that made some sense?!

Link to comment
Share on other sites

Link to post
Share on other sites

You need Registry.SetValue()

Microsoft has a nice example on how to read/write registry values here: https://msdn.microsoft.com/en-us/library/microsoft.win32.registry.setvalue(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

 

Remember, that if you want to write under HKEY_LOCAL_MACHINE you need to run your program with elevated credential (true admin).

Link to comment
Share on other sites

Link to post
Share on other sites

31 minutes ago, GoodBytes said:

You need Registry.SetValue()

Microsoft has a nice example on how to read/write registry values here: https://msdn.microsoft.com/en-us/library/microsoft.win32.registry.setvalue(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

 

Remember, that if you want to write under HKEY_LOCAL_MACHINE you need to run your program with elevated credential (true admin).

I'm trying to CREATE a key not SETVALUE. I also know that I need to be running the program as true administrator

Link to comment
Share on other sites

Link to post
Share on other sites

Sorry,you want to create a key (folder) or value (DWORD (number), String)?

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

12 hours ago, GoodBytes said:

Sorry,you want to create a key (folder) or value (DWORD (number), String)?

 

 

 

Trying to create the string, mate. :)

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, AgentEddie99 said:

Trying to create the string, mate. :)

Ok, Keys (folders) are called "Keys", because the registry is actually a database.. just the Regedit make it look like a folder structure for easier understanding.

 

-> So you need to make sure the Key (folder) exists before you can create and define a string, if not, you need to create it

-> You then need to Open the key that you want to work in. (again, because we are working with a database, that is how it works)

-> Then you can create and define your string (REG_SZ), with Registry.SetValue

 

 

In other words: RegOpenKeyEx to open the key.

If it fails -> Key doesn't exists, create it (RegCreateKeyEx), then open it (RegOpenKeyEx).

If success -> ready to read/write.

Once the key is open, now create your string (RegSetValueEx), or read it (RegSetValueEx).

 

RegOpenKeyEx, RegCreateKeyEx, RegOpenKeyEx, RegSetValueEx, RegSetValueEx, are all C/C++. You need to find the VB .NET equivalent

 

:)

 

Sorry I can't give you code, as I don't know VB. But look into those.

So: Check if key exists, if not create key (or just create key, if you are lazy),

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, GoodBytes said:

Ok, Keys (folders) are called "Keys", because the registry is actually a database.. just the Regedit make it look like a folder structure for easier understanding.

 

-> So you need to make sure the Key (folder) exists before you can create and define a string, if not, you need to create it

-> You then need to Open the key that you want to work in. (again, because we are working with a database, that is how it works)

-> Then you can create and define your string (REG_SZ), with Registry.SetValue

 

:)

 

Sorry I can't give you code, as I don't know VB. But look into those.

I know all about what the registry is. I'm looking for a way to create the string in VB code. Thanks for the information. I have done some research my self on the matter.

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, AgentEddie99 said:

I know all about what the registry is. I'm looking for a way to create the string in VB code. Thanks for the information. I have done some research my self on the matter.

 

Sorry, I am just trying to see where you are at, as I don't see your code :)

 

But SetValue should work, if it does not, then you didn't open the key successfully, or your program is not running as elevated credential.

Try reading something first, as for writing the code is identical, just write function instead of read. See if that works first.

 

But from this example:

https://msdn.microsoft.com/en-us/library/k23f0345(v=vs.110).aspx

Looking at this line:

rk.SetValue("StringValue", "The path is %PATH%", RegistryValueKind.String) 

It looks straight forward.

First argument (from left to right, of course) is the name of the String, the second argument is its value, and the last argument is the type, in this case String value.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, GoodBytes said:

Sorry, I am just trying to see where you are at, as I don't see your code :)

 

But SetValue should work, if it does not, then you didn't open the key successfully, or your program is not running as elevated credential.

Try reading something first, as for writing the code is identical, just write function instead of read. See if that works first.

 

But from this example:

https://msdn.microsoft.com/en-us/library/k23f0345(v=vs.110).aspx

Looking at this line:


rk.SetValue("StringValue", "The path is %PATH%", RegistryValueKind.String) 

It looks straight forward.

I have dried that and I have come to a dead end.

 

Link to comment
Share on other sites

Link to post
Share on other sites

I made something like this:

Imports System
Imports Microsoft.Win32

Module Module1

    Sub Main()
        Dim lmReg As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", True)

        lmReg.SetValue("Test", "Test value")
        lmReg.Close()


        Console.ReadLine()

    End Sub

End Module

But if you build you app without specifying platform, it may be either x64 or x86, so 64 or 32 bit, and for 32 bit above code will add Test value into 

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\OEMInformation

When you set it to run on 64 bit, it will create value in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation

And another thing, you may run into permissions exception issue, I have my UAC disabled so I don't know, but if it will happen for you, you need to change your manifest/project settings so your application will start with administrator rights.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×