I was using VBScript method of registrywriting which is more than easy. But, when I am trying to write to registry through RegOpenKeyEx, I am having problem(s).
Here is what I tried:
'_____________________________________________________
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hkey As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
(ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, ByRef phkResult 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 Any, ByVal cbData As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H2003F
Private Sub Form_Load()
Dim hkey As Long, ret As Long, rett As Long
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_ALL_ACCESS, hkey)
rett = RegSetValueEx(hkey, App.EXEName, 0, REG_SZ, "e:\myprog.exe" & vbNullChar, Len("e:\myprog.exe") + 1)
RegCloseKey (hkey)
End Sub
'_____________________________________________________
It does make the SubKey but the value is something like:
,qT instead of e:\myprog.exe
If you have a sample code then please post one...
Thanks.
Here is what I tried:
'_____________________________________________________
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hkey As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" _
(ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, ByRef phkResult 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 Any, ByVal cbData As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H2003F
Private Sub Form_Load()
Dim hkey As Long, ret As Long, rett As Long
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_ALL_ACCESS, hkey)
rett = RegSetValueEx(hkey, App.EXEName, 0, REG_SZ, "e:\myprog.exe" & vbNullChar, Len("e:\myprog.exe") + 1)
RegCloseKey (hkey)
End Sub
'_____________________________________________________
It does make the SubKey but the value is something like:
,qT instead of e:\myprog.exe
If you have a sample code then please post one...
Thanks.