• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Editing the registry with VB?

loosbrew

Golden Member
hey all,
im new to VB and cant figure out how to edit a specific reg key with VB. what i really need is to create or change an enviromental variable with a VB. I need to design a simple little window that has one text line where one can enter the data and once the "OK" button is clicked, the data will be entered into the reg key that is specified in the code of the mini app.

if anyone can help me find a website to point me in the right direction of how to get this accomplished, i would appreciate it tremendously! i know this has to be very easy in VB!

Thanks
loosbrew
 
Last time I looked (many, many moons ago) there was no MS provided control for registry editing and all the ones I found were commercial with very steep price tags. You can tell VB to import functions from any DLL on the system and you can use the native Win32 registry functions, not the easiest but it works.
 
then how about adding an system environmental variabl through VB? it cant be that hard can it?, i just cant find any info on how to do it!

loosbrew
 
All the environment variables are stored in the registry.

Have you checked out MSDN? I havn't touched VB in years and thankfully I've forgotten most of it =)
 
You could use the WINAPI, but it isn't easy. I would recommend you use the WScript.Shell ActiveX control which is used primarily by Windows Scripting Host. Just add a reference to C:\WINNT\SYSTEM32\wshom.ocx or load the control at runtime using this code:

Set oShell = CreateObject("WScript.Shell")
oShell.RegWrite "HKEY_CURRENT_USER\Software\KB\Version", "1.000"

Set oShell = Nothing

Here is the Object reference http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsobjwshshell.asp
 
You could have the VB app write a .reg file to disk then shell the write out to regedit. Like


open "edit.reg" for output as #1
print #1, "REGEDIT 4"
print #1, ""
print #1, "registry key thingie here"
close #1
shell("command.com /c regedit /s edit.reg")

You might want to make sure I have all the syntax correct, doing this quickly off the top of my head.
It isn't pretty, but it does work.

Bot
 
Don't listen to any of these people.

You can access the registry natively with VB using GetSetting, SaveSetting, etc. The knock on this is that all of your registry entries are saved under something like Software>Microsoft>VB and VBA settings. If this doesn't matter to you, go ahead and use it.

If you want more control over where the registry entries are saved, then go here and get RegSettings.zip. You'll find it under samples.
 
Back
Top