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?
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:
RegCreateKey &H80000001, "Software\Microsoft\Windows\CurrentVersion\Run\", RegKey
RegSetValueEx RegKey, "testing", 0, 1, "temp", 4
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.
Re: Problem writing to registry
Quote:
Originally Posted by INF3RN0666
but I think i'm supposed to pass my strings ByVal
Correct.
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...
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.
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...