Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to registry using VBA 2

Status
Not open for further replies.

SkyHigh

Technical User
May 30, 2002
309
0
0
CA
Hi Folks

I need some routines in VBA to check if a registry entery exists if not then add it.

The registry entries required are as under

HKEY_LOCAL_MACHINE/SOFTWARE/PetersSoftware/Button Painter, Install Folder C:/Programme files/Peters Software/Button Painter

HKEY_LOCAL_MACHINE/SOFTWARE/PetersSoftware/Button Painter,Product Key 111100011

Thanks much.
Brenda

 
Can someone please help
Thanks!!
 
Adaptated from the Windows Scripting help file:
WSHhelp said:
Dim WshShell, bKey
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\MindReader", "Goocher!", "REG_SZ"
bKey = WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\")
Debug.Print WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\MindReader")
WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\MindReader"
WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\"
WshShell.RegDelete "HKCU\Software\ACME\"
You may reference the Microsoft Scripting Runtime.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Excellent post PHV, enjoy your star!

One small correction, if Brenda wants to use early binding, the library reference she needs is Windows Script Host Object Model (wshom.ocx), not the Scripting Runtime as you suggest. It is irritating that this isn't listed with the rest of the Microsoft objects because I never remember that and always have to go looking for it when I need it.

Have a great day!

j2consulting@yahoo.com
 
A couple additional questions:

1. From your code, it appears bkey is an array of keys. Is there an items collection and, if so, how do you reference it as a collection member (eg Sheets(1) or Sheets("Sheet1")

2. Do you recommend any resources for learning more about this subject

Thanks!

Have a great day!

j2consulting@yahoo.com
 
Great PHV !!
Thanks for coming to my help once again !!
Brenda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top