Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Reading and Righting to registry

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
asdf103100
Asked:
asdf103100
  • 4
  • 3
1 Solution
 
bukkoCommented:

Use WScript.Shell

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

bukko
0
 
bukkoCommented:

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
 
bukkoCommented:

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
J-ManCommented:
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
 
asdf103100Author Commented:
what does the script do? also its comming back with the problem that the key is not found
0
 
asdf103100Author Commented:
what does the script do? also its comming back with the problem that the key is not found
0
 
asdf103100Author Commented:
this is a perfect example, thank you.
0
 
asdf103100Author Commented:
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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now