Results 1 to 12 of 12

Thread: Editing registry In VB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    144

    Editing registry In VB

    in VB how is it possible to make changes to the registry.

    basically i want to be able 2 switch between 2 servers but the server "domain,ip"; is stored in the registry so i want to add 2 command buttons to my form.

    Command 1 = Connect To Original Server
    - will change the domain and ip to the original server

    Command 2 = Connect To My Server
    - will change the domain and ip to my server address

    and also maybe have a check to know what server they are on.
    if they connect to original server it displays some information in a text box or somethin... and if they connect to mine i can get it to display some of my server info. and if they are connected to my server and they attempt to press again a msg box will appear saying "already Connnected To This Server"

    i can see this being alot of coding but if anyone can offer any help, tutorials or sample codes to get me started that would b great!

  2. #2
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589
    There are two methods GetSetting and SaveSetting use them to edit the registry..
    HTH

  3. #3
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    Originally posted by sridharavijay
    There are two methods GetSetting and SaveSetting use them to edit the registry..
    HTH
    there are more then just 2 methods. these are built-in functions of VB. However if you really want to do things like adding keys, adding/editing values, deleting keys, etc. you are going to have to use the API functions to deal with the registry

  4. #4
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    go here to learn more about API's


    http://www.mentalis.org/index2.shtml

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    144
    all i want is a command button that once clicked it will change a key in the registry

  6. #6
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    what key are you looking at changing?


    one other note i would also suggest downloading the API-Guide 3.7 from that site that I told you about in my previous post

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    144
    [HKEY_CURRENT_USER\Software\Microsoft\MessengerService]server="messenger.hotmail.com;63.13.17.64";

    and

    [HKEY_CURRENT_USER\Software\Microsoft\MSNMessenger]
    server="messenger.hotmail.com"

    to my own server values...

  8. #8
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    what OS are you running just so i know?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    144
    windows 2k

  10. #10
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    ok like i said you may want to go to that website however here is a snippet of code that i got from there website. i would send you something that i have but i'm not at the computer that has the project i'm working one for the day. but here i hope this helps


    VB Code:
    1. 'This program needs 3 buttons
    2. Const REG_SZ = 1 ' Unicode nul terminated string
    3. Const REG_BINARY = 3 ' Free form binary
    4. Const HKEY_CURRENT_USER = &H80000001
    5. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    6. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    7. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    8. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    9. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    10. 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
    11. Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
    12.     Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
    13.     'retrieve nformation about the key
    14.     lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
    15.     If lResult = 0 Then
    16.         If lValueType = REG_SZ Then
    17.             'Create a buffer
    18.             strBuf = String(lDataBufSize, Chr$(0))
    19.             'retrieve the key's content
    20.             lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
    21.             If lResult = 0 Then
    22.                 'Remove the unnecessary chr$(0)'s
    23.                 RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
    24.             End If
    25.         ElseIf lValueType = REG_BINARY Then
    26.             Dim strData As Integer
    27.             'retrieve the key's value
    28.             lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
    29.             If lResult = 0 Then
    30.                 RegQueryStringValue = strData
    31.             End If
    32.         End If
    33.     End If
    34. End Function
    35. Function GetString(hKey As Long, strPath As String, strValue As String)
    36.     Dim Ret
    37.     'Open the key
    38.     RegOpenKey hKey, strPath, Ret
    39.     'Get the key's content
    40.     GetString = RegQueryStringValue(Ret, strValue)
    41.     'Close the key
    42.     RegCloseKey Ret
    43. End Function
    44. Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
    45.     Dim Ret
    46.     'Create a new key
    47.     RegCreateKey hKey, strPath, Ret
    48.     'Save a string to the key
    49.     RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
    50.     'close the key
    51.     RegCloseKey Ret
    52. End Sub
    53. Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    54.     Dim Ret
    55.     'Create a new key
    56.     RegCreateKey hKey, strPath, Ret
    57.     'Set the key's value
    58.     RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
    59.     'close the key
    60.     RegCloseKey Ret
    61. End Sub
    62. Sub DelSetting(hKey As Long, strPath As String, strValue As String)
    63.     Dim Ret
    64.     'Create a new key
    65.     RegCreateKey hKey, strPath, Ret
    66.     'Delete the key's value
    67.     RegDeleteValue Ret, strValue
    68.     'close the key
    69.     RegCloseKey Ret
    70. End Sub
    71. Private Sub Command1_Click()
    72.     Dim strString As String
    73.     'Ask for a value
    74.     strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title)
    75.     If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then
    76.         MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title
    77.         Exit Sub
    78.     End If
    79.     'Save the value to the registry
    80.     SaveStringLong HKEY_CURRENT_USER, "KPD-Team", "BinaryValue", CByte(strString)
    81. End Sub
    82. Private Sub Command2_Click()
    83.     'Get a string from the registry
    84.     Ret = GetString(HKEY_CURRENT_USER, "KPD-Team", "BinaryValue")
    85.     If Ret = "" Then MsgBox "No value found !", vbExclamation + vbOKOnly, App.Title: Exit Sub
    86.     MsgBox "The value is " + Ret, vbOKOnly + vbInformation, App.Title
    87. End Sub
    88. Private Sub Command3_Click()
    89.     'Delete the setting from the registry
    90.     DelSetting HKEY_CURRENT_USER, "KPD-Team", "BinaryValue"
    91.     MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title
    92. End Sub
    93. Private Sub Form_Load()
    94.     'KPD-Team 1998
    95.     'URL: [url]http://www.allapi.net/[/url]
    96.     'E-Mail: [email][email protected][/email]
    97.     Command1.Caption = "Set Value"
    98.     Command2.Caption = "Get Value"
    99.     Command3.Caption = "Delete Value"
    100. End Sub

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    144
    many thanks i will try out the code now and check out the site

  12. #12
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    you are going to have to modify the code a bit, but it is something to get you started

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