?
Solved

Reading and Righting to registry

Posted on 2003-03-02
8
Medium Priority
?
148 Views
Last Modified: 2010-05-01
Hey i have been trying to find everywhere a good tutorial that would actualy work for me but unfortunately i have not been able to what i want to do is open up a key in the registry using visual basics api.  What i want to open up is the key located under HKEY_CURRENT_USER\Valve\Half-Life\InstallPath and then get the install path from there.   What im lookin for in the answer is an exmple piece of code that will get that also its a reg_sv variable just incase you need to know for the answer.  What i want is an example with the appropriat comments that will get that and teach me how to input that data OR a website that will tell me how (must work for vb 6.0).
0
Comment
Question by:asdf103100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:bukko
ID: 8053621

Use WScript.Shell

...I'll put some code together and post.

bukko
0
 
LVL 8

Expert Comment

by:bukko
ID: 8053636

Public Function GetRegValue( strRegPath As String ) As String
    Dim objWSH As Object
   
    Set objWSH = CreateObject("WScript.Shell")
    GetRegValue = objWSH.RegRead( strRegPath )
   
    Set objWSH = Nothing

End Function


To use...

MyValue = GetRegValue("HKEY_CURRENT_USER\Valve\Half-Life\InstallPath")
Debug.Print MyValue


Regards

bukko
0
 
LVL 8

Expert Comment

by:bukko
ID: 8053677

To write...

Public Function SetRegValue( strRegPath As String, strValue As String ) As String
   Dim objWSH As Object
   
   Set objWSH = CreateObject("WScript.Shell")
   objWSH.RegWrite strRegPath, strValue
   
   Set objWSH = Nothing

End Function

To use...

SetRegValue "HKEY_CURRENT_USER\Valve\Half-Life\InstallPath", strMyValue

Regards

bukko
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
J-Man earned 400 total points
ID: 8053757
http://www.freevbcode.com/ShowCode.Asp?ID=314

This website has excellent example code for registry functions with windows api.
For your case you need to know the two functions: RegOpenKey, and RegQueryValueEx.
Constant enumerations are also listed for key locataions (i.e. HKEY_CURRENT_USER), access rights, value types, and return codes.

This is a large example with code to check if a key exists, create, read, write and delete keys/values.

Enjoy.
0
 

Author Comment

by:asdf103100
ID: 8053928
what does the script do? also its comming back with the problem that the key is not found
0
 

Author Comment

by:asdf103100
ID: 8053958
what does the script do? also its comming back with the problem that the key is not found
0
 

Author Comment

by:asdf103100
ID: 8054868
this is a perfect example, thank you.
0
 

Author Comment

by:asdf103100
ID: 8061983
what does the script do? also its comming back with the problem that the key is not found
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question