VBS/VBA/VB and registry editing...

General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
Post Reply
User avatar
rmrucker
Posts: 896
Joined: Sun Sep 17, 2000 12:00 pm
Location: Long Beach, CA, USA

VBS/VBA/VB and registry editing...

Post by rmrucker »

Help a dumb and confused newbie.

If I use VBScript or even VBA, I can edit the registry by Creating the Windows Scripting Host Shell Object and then using simple commands like RegWrite or RegDelete:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite ...

However, as best I can tell, this is not an option for VB6. To edit the registry using VB6, I need to:

1) Declare each editing function from advapi32.dll separately (e.g., Declare Function RegSetValueEx...)
2) Declare each parameter I might use with a given function (e.g., hkey, ipValueName)
3) Declare a Type for each parameter (e.g., As Long).
4) Define Constants for the hives and data values (e.g., Const REG_SZ = 1)
5) Define Constants for registry permisions (e.g., Const KEY_WRITE = &H20006)

Then, I can use VB6 to edit the registry. Is this a correct assumption??

Is there no way to invoke the Windows Scripting Host Shell Object in VB6 like I can in VBS and VBA?

Also, can I stick ALL the Declarations and Constants I need to edit the registry in single ".bas" module, and then 'refer to' or 'call on' this module each time I want to have a VB6 program edit the registry?

Please respond as you would to an eight year old. Some people have said I frequently act that old anyway! ;-] THANK YOU.
User avatar
parse27
Regular Member
Posts: 157
Joined: Thu Jun 20, 2002 1:34 pm
Location: 10,000 dreams and climbing

Post by parse27 »

yes i think you can stick ALL the Declarations and Constants you'll
need to edit the registry in single ".bas" module, then refer to that module when you need it.

if you don't mind my asking, what part of the registry would you like to write to? what would you like to write?

:D
skipping sunbeams :)
User avatar
rmrucker
Posts: 896
Joined: Sun Sep 17, 2000 12:00 pm
Location: Long Beach, CA, USA

Post by rmrucker »

I have multiple projects planned... now how many will really get done, that is another story. ;)

I found out I actually CAN use the WshShell object to edit the registry in VB6. The code should be this instead:

Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite ...

I simply don't put the WScript. before the CreateObject.
User avatar
parse27
Regular Member
Posts: 157
Joined: Thu Jun 20, 2002 1:34 pm
Location: 10,000 dreams and climbing

Post by parse27 »

just noticed too..you made the CreateObject method a property of WScript the first time you did it..

gud thing you got it..i wonder what you need the registry access for? hmm... :D
skipping sunbeams :)
Post Reply