We help IT Professionals succeed at work.

Set Value in Registry : RegSetValueEx  API...

jom080298
jom080298 asked
on
873 Views
Last Modified: 2012-05-04
I need to access to the Windows Registry sush as set it value or get value from it. So, this is my code:

   Dim m_hKey as long
   Dim data as String
   data = "Hello, World"

   RegCreateKey HKEY_LOCAL_MACHINE, "Software\JOM", m_hKey
   RegSetValue m_hKey, "MyWord", 0, REG_SZ, data, Len(data)

    the result is, the subkey JOM was created and Value name MyWord was created ,too but its value was not "Hello, World", there are 2-3 characters.

    How can I do.?
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you very much.

Author

Commented:
To Waty,
      now I can set the value the the registry but it can set just the string value, can not set the integer or long, because you change the declare function of RegSetValueEx on the lpData parameter to ByVal lpData as String. So, please help me again to can set the value both String and Int or Long.

Waiting for your help.

Commented:
You can add those declaration and modify the class I gave you.

Private Declare Function RegSetValueExLong Lib "advapi32" Alias "RegSetValueExA" _
  (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
   ByVal dwType As Long, szData As Long, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExByte Lib "advapi32" Alias "RegSetValueExA" _
  (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, _
   ByVal dwType As Long, szData As Byte, ByVal cbData As Long) As Long



Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.