CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    Setting Registry Value

    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.



  2. #2

    Re: Setting Registry Value

    what's your API declaration?

    hi,brt

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

  3. #3
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    Re: Setting Registry Value

    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


  4. #4

    Re: Setting Registry Value

    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/im...ertaplanet.gif'>
    </center>

  5. #5
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    Re: Setting Registry Value

    Nope, it didn't work. Gives the same error code
    i.e., 998

    Regards.


  6. #6

    Re: Setting Registry Value

    sorry U must use REG_SZ instead of REG_DWORD..

    hi,brt

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

  7. #7
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    Re: Setting Registry Value

    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?


  8. #8
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Setting Registry Value

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured