Results 1 to 11 of 11

Thread: stupid values given from Registry Code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271

    Unhappy stupid values given from Registry Code

    hi,

    I'm using VB.NET to edited the registry and when I try to add a string to the registry the value ends up encrypted (or thats what it looks like)

    when I set the value to be any thing it gives me a ä for some reason.

    heres the code I'm using:

    Module:


    VB Code:
    1. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Integer) As Integer
    2.     Declare Function RegCreateKey Lib "advapi32.dll"  Alias "RegCreateKeyA"(ByVal HKEY As Integer, ByVal lpSubKey As String, ByRef phkResult As Integer) As Integer
    3.     Declare Function RegDeleteKey Lib "advapi32.dll"  Alias "RegDeleteKeyA"(ByVal HKEY As Integer, ByVal lpSubKey As String) As Integer
    4.     Declare Function RegDeleteValue Lib "advapi32.dll"  Alias "RegDeleteValueA"(ByVal HKEY As Integer, ByVal lpValueName As String) As Integer
    5.     Declare Function RegOpenKey Lib "advapi32.dll"  Alias "RegOpenKeyA"(ByVal HKEY As Integer, ByVal lpSubKey As String, ByRef phkResult As Integer) As Integer
    6.     Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal lpReserved As Integer, ByRef lpType As Integer, ByRef lpData As String, ByRef lpcbData As Integer) As Integer
    7.     Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal lpReserved As Integer, ByRef lpType As Integer, ByRef lpData As Integer, ByRef lpcbData As Integer) As Integer
    8.     Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal Reserved As Integer, ByVal dwType As Integer, ByRef lpData As String, ByVal cbData As Integer) As Integer
    9.     Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Integer, ByVal lpValueName As String, ByVal Reserved As Integer, ByVal dwType As Integer, ByRef lpData As Integer, ByVal cbData As Integer) As Integer
    10.     Public Const HKEY_CLASSES_ROOT = &H80000000
    11.     Public Const HKEY_CURRENT_USER = &H80000001
    12.     Public Const HKEY_LOCAL_MACHINE = &H80000002
    13.     Public Const HKEY_USERS = &H80000003
    14.     Public Const HKEY_PERFORMANCE_DATA = &H80000004
    15.     Public Const REG_SZ = 1
    16.    
    17.     Function RegQueryStringValue(ByVal HKEY As Integer, ByVal strValueName As String) As Object
    18.         Dim ERROR_SUCCESS As Object
    19.         Dim lResult As Integer
    20.         Dim lValueType As Integer
    21.         Dim strBuf As String
    22.         Dim lDataBufSize As Integer
    23.        
    24.         On Error GoTo 0
    25.         lResult = RegQueryValueEx(HKEY, strValueName, 0, lValueType, 0, lDataBufSize)
    26.         If lResult = ERROR_SUCCESS Then
    27.             If lValueType = REG_SZ Then
    28.                 strBuf = New String(" ", lDataBufSize)
    29.                 lResult = RegQueryValueEx(HKEY, strValueName, 0, 0, strBuf, lDataBufSize)
    30.                 If lResult = ERROR_SUCCESS Then
    31.                     RegQueryStringValue = StripTerminator(strBuf)
    32.                 End If
    33.             End If
    34.         End If
    35.     End Function
    36.    
    37.     Public Function GetSettingEx(ByRef HKEY As Integer, ByRef sPath As String, ByRef sValue As String) As Object
    38.         Dim KeyHand As Integer
    39.         Dim datatype As Integer
    40.         Call RegOpenKey(HKEY, sPath, KeyHand)
    41.         GetSettingEx = RegQueryStringValue(KeyHand, sValue)
    42.         Call RegCloseKey(KeyHand)
    43.     End Function
    44.    
    45.     Function StripTerminator(ByVal strString As String) As String
    46.         Dim intZeroPos As Short
    47.        
    48.         intZeroPos = InStr(strString, Chr(0))
    49.         If intZeroPos > 0 Then
    50.             StripTerminator = Left(strString, intZeroPos - 1)
    51.         Else
    52.             StripTerminator = strString
    53.         End If
    54.     End Function
    55.    
    56.     Public Sub SaveSettingEx(ByRef HKEY As Integer, ByRef sPath As String, ByRef sValue As String, ByRef sData As String)
    57.         Dim KeyHand As Integer
    58.         Call RegCreateKey(HKEY, sPath, KeyHand)
    59.         Call RegSetValueEx(KeyHand, sValue, 0, REG_SZ, sData, Len(sData))
    60.         Call RegCloseKey(KeyHand)
    61.     End Sub


    Form:

    VB Code:
    1. Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
    2. SaveSettingEx(HKEY_LOCAL_MACHINE, "Software\Studz\", "test", "1")
    3. end sub


    Is there anything wrong with mycode?

    any help would be great.

    thanks
    Last edited by §tudz; Feb 10th, 2003 at 12:48 PM.
    §tudz

    Studzworld.com - Portfolio

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , you have an attractive Class to use !It has all methods that you need to do all operations against the Registry .
    have a look at this tutorial !

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    thanks for that, I take a look and see what I can do with it.

    Do you know what is wrong with my Class?

    Thanks
    §tudz

    Studzworld.com - Portfolio

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I've not looked at it but , you seem still using API although you have the best alternative which is the Registry Class !

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    ok,

    that doesn't work at all?

    could it be something to do with using WinXP Pro?
    §tudz

    Studzworld.com - Portfolio

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    No matter, that problem was I put the delete Key function in, so when it made the striong it then deleted it...


    DUH!! I'm stupid some times

    Thanxs for the help
    §tudz

    Studzworld.com - Portfolio

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Post your code !

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    PLEASE tell me you are NOT using the code you posted above!!!!!!!!!!!! PLEASE I BEG YOU, use the built in registry objects under the Microsoft namespace. You will laugh when you realize how easy it is.

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    lol ... .I think he still .

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271
    no, I'm using the built in class now. I just left the string delete value in, form the example.

    just a query, what was wrong with my class? why did it produce incorrect values?
    §tudz

    Studzworld.com - Portfolio

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't know but I think the consts are have values that can be applied to the win98 , me Registries !maybe not !

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