Results 1 to 7 of 7

Thread: Problem writing to registry

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    Problem writing to registry

    Hi,
    I'm trying to write to the registry in vista while trying to adhere to the User Access Control guidelines. I can write to the registry, but the data written ends up as random letters. take a look at the code i'm using:

    [vbcode]
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As String, ByVal cbData As Long) As Long

    Dim RegKey as Long
    RegCreateKey &H80000001, "Software\Microsoft\Windows\CurrentVersion\Run\", RegKey
    RegSetValueEx RegKey, "testing", 0, 1, "temp", 4
    RegCloseKey (RegKey)
    [/vbcode]

    When I go to check the registry, the key name "testing" is fine, but the value of it "temp" ends up looking like "L.". Any ideas?

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Problem writing to registry

    Perhaps you are writing in BINARY instead of STRING....

    We can't tell what you are doing since you used numbers instead of the const variables to state exactly what you are attempting to do... We don't memorize the numbers...
    vb Code:
    1. RegCreateKey &H80000001, "Software\Microsoft\Windows\CurrentVersion\Run\", RegKey
    2. RegSetValueEx RegKey, "testing", 0, 1, "temp", 4

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    Re: Problem writing to registry

    Oh i never thought of that. Funny thing is, I copied the number for string but i'll double check.
    ...checking...
    Nope, it turns out that the string constant is "1", but I think i'm supposed to pass my strings ByVal. I dunno how that will affect it.

  4. #4
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Problem writing to registry

    Quote Originally Posted by INF3RN0666
    but I think i'm supposed to pass my strings ByVal
    Correct.

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Problem writing to registry

    Quote Originally Posted by INF3RN0666
    Oh i never thought of that. Funny thing is, I copied the number for string but i'll double check.
    ...checking...
    Nope, it turns out that the string constant is "1", but I think i'm supposed to pass my strings ByVal. I dunno how that will affect it.
    If you used the constants in your code you would NEVER create that mistake again...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    Re: Problem writing to registry

    i have no idea how you know what the constants are. i just find code and it has some of the constants here and there.

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Problem writing to registry

    A quick Google search http://msdn.microsoft.com/en-us/library/aa460588.aspx

    Don't follow the not so bright follow the bright...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width