Click to See Complete Forum and Search --> : Setting Registry Value


Green_Beret
August 29th, 2001, 04:35 AM
Hi All,

I'm trying to set a DWORD value in the Win2k System Registry using RegSetValueExA. But it is giving an Error 998.
Can anyone tell me what am I doing wrong?

Here's the function call :
dim setval as long

setval = 10

RegFuncRetval = RegSetValueExA _
(phk, _
"Status_Code", 0&, REG_DWORD, _
setval, 4)

Here phk has been obtained from an earlier call to RegOpenKeyExA

Please help.
Thanks.

berta
August 29th, 2001, 05:13 AM
what's your API declaration?

hi,brt

<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

Green_Beret
August 29th, 2001, 05:15 AM
Public Declare Function RegSetValueExA Lib "advapi32.dll" _
(ByVal hKey As Long, ByVal lpValueName As _
String, ByVal Reserved As Long, ByVal dwType As Long, ByVal _
lpValue As Any, ByVal cbData As Long) As Long

berta
August 29th, 2001, 05:22 AM
try this:

dim strData as string
strData= "10"

RegFuncRetval = RegSetValueExA _
(phk, _
"Status_Code", 0&, REG_DWORD, ByVal strData, LenB(StrConv(strData, vbFromUnicode)) + 1)

hi,brt

<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

Green_Beret
August 29th, 2001, 06:02 AM
Nope, it didn't work. Gives the same error code
i.e., 998

Regards.

berta
August 29th, 2001, 06:05 AM
sorry U must use REG_SZ instead of REG_DWORD..

hi,brt

<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

Green_Beret
August 29th, 2001, 06:16 AM
It puts the ASCII codes for the chars that make up the string. So for "10" it sets the value to
3031 in Hex .How do I work this around?

Iouri
August 29th, 2001, 08:19 AM
Sub RegWrite(RegKey As String, RegValue As Integer)
'==============================================
Dim RegEdit As Object

' Create the RegEdit Object
Set RegEdit = CreateObject("WScript.Shell")

' Set The Value
RegEdit.RegWrite RegKey, RegValue, "REG_DWORD"

Set RegEdit = Nothing
End Sub

This will enter the DWORD value to the registry

Iouri Boutchkine
iouri@hotsheet.com