Results 1 to 40 of 40

Thread: [RESOLVED] Registry Manipulation ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Resolved [RESOLVED] Registry Manipulation ?

    Well, this site is my only other options
    can someone please explain how to read / write to the registry,
    Im quite knew to VB, myknowledge is somewhat 'dim' (get it? xD..-.- okay, i'll stop :>)

    I've read about 5/6 tutorials on how to manipulate the registry and none of them actually made any sense what so ever x\
    so please, a shout out to all you vb guru's - help pls :P

    greetz
    kings x)

  2. #2
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Registry Manipulation ?

    search the forum....

    this has been discussed many times before... im sure something usefull would come out..
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Bleh. too much to look through, and most isnt really that relevant
    I mean, can anyone acually take me through step by step, or
    Last edited by kingzl3y; Apr 8th, 2007 at 04:34 PM.

  4. #4
    Fanatic Member
    Join Date
    Oct 2005
    Posts
    586

    Re: Registry Manipulation ?

    Ok... here's a sample

    Save a text string:
    Text$="Stuff to Save"
    SaveSetting "MyProgram", "MySection", "TextValue1", Text$

    Get your strng back
    Text$= GetSetting("MyProgram", "MySection", "TextValue1", Default:="")

    Easy stuff.

    --DB

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Registry Manipulation ?

    Quote Originally Posted by kingzl3y
    Bleh. too much to look through, and most isnt really that relevant
    I mean, can anyone acually take me through step by step, or
    That depends on the specifics of what you want to do.

    What are those specifics?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    thnx for the replies (:
    Well, specifics? at the moment there are none.
    But next week, in college..i get my 2nd VB assingment and in that assingment..i have to create a program which saves stuff to the registry - im not sure what or what..or even when..but all i know is that its coming o_0

    Thankx darkbob,
    Could you go into a bit more detail in that for me? if it isnt too much trouble...lets say i wanted to read the location(Or data) of "H/PC Connection Agent" in
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run


    How would i go about doing that - btw, thats just an example >

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    bump :'(
    Last edited by kingzl3y; Apr 9th, 2007 at 06:25 PM.

  8. #8
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Quote Originally Posted by kingzl3y
    thnx for the replies (:
    Well, specifics? at the moment there are none.
    But next week, in college..i get my 2nd VB assingment and in that assingment..i have to create a program which saves stuff to the registry - im not sure what or what..or even when..but all i know is that its coming o_0

    Thankx darkbob,
    Could you go into a bit more detail in that for me? if it isnt too much trouble...lets say i wanted to read the location(Or data) of "H/PC Connection Agent" in
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run


    How would i go about doing that - btw, thats just an example >
    Darkbob's code does precisecely that. FYI there are approximately 90 registry/ini API's, and on top of that you can also use WMI and Regedit.exe. It's a huge subject, and although forum members are willing to help on specific issues, I doubt anyone will do a tutorial. That's what colleges are for.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Quote Originally Posted by schoolbusdriver
    Darkbob's code does precisecely that. FYI there are approximately 90 registry/ini API's, and on top of that you can also use WMI and Regedit.exe. It's a huge subject, and although forum members are willing to help on specific issues, I doubt anyone will do a tutorial. That's what colleges are for.
    Okay Schoolbus'
    Thanks for putting it bluntly xD
    Okay, you said Darkbob's code does exactly that? right? well anychance you can just post an example of that... becuase i've tried it..and well..bummèr does work
    College wont go in to too much detail about registry..becuase you can near enough 'hack' your way through alot of things.
    So anyone got a working example,
    and btw i didnt mean a tutorial..just like point me in the right direction x].
    Also, you mentioned there are 90 Registry/ini API's - which are x[....

  10. #10
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Using Get/SaveSetting is quite straightforward. It only saves to "HKEY_CURRENT_USER\Software\VB and VBA Program Settings". This example will save in the subkey "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\RegistryTest\My Subkey"

    vb Code:
    1. 'Needs 2 command buttons and 3 textboxes.
    2.  
    3. Public Const MY_TESTKEY = "RegistryTest"
    4.  
    5. Private Sub cmdSave_Click()
    6. 'Add some test values.
    7.    txtSubkey.Text = "My Subkey"
    8.    txtValueName.Text = "My Value Name"
    9.    txtValue.Text = "My Value"
    10.  
    11.    On Error GoTo SaveError
    12.       SaveSetting MY_TESTKEY, txtSubkey.Text, txtValueName.Text, txtValue.Text
    13.    Exit Sub
    14. SaveError:
    15.    MsgBox ("Error in cmdSave_Click")
    16.    Exit Sub
    17. End Sub
    18.  
    19. Private Sub cmdGet_Click()
    20.    On Error GoTo GetError
    21.       txtValue.Text = GetSetting(MY_TESTKEY, txtSubkey.Text, txtValueName.Text, "Default")
    22.    Exit Sub
    23. GetError:
    24.    MsgBox ("Error in cmdGet_Click")
    25.    Exit Sub
    26. End Sub

    Saving to somewhere like "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" is a bit harder and can only be done using the APIs. At couple of my previous posts show how to do this.

    More info:

    Registry APIs:
    http://msdn2.microsoft.com/en-us/library/ms724875.aspx

    WMI:
    http://msdn2.microsoft.com/en-us/library/aa394573.aspx
    WMI StdRegProv:
    http://msdn2.microsoft.com/en-us/library/aa393664.aspx

    Windows Script Host:
    http://msdn.microsoft.com/archive/de...htm/WSHtoc.asp

    Regedit:
    Google for "regedit command line". You'll get links like:
    http://techsupt.winbatch.com/ts/T000001029F18.html

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Lol, thanks alot 'driver, helped me alot
    Okay.
    I looked at all the links you provided, i think the one that made most sense was the ......well...im not even sure which one it was now ><
    but i know it mentioned something about using erm,
    Code:
     Set Create = CreateObject("wscript.shell")
    ..i had a look, and deiced to see if i could find anyworking examples..
    I did.
    Its a IE proxy Changer(Which is what i needed..but not no more, found one (: )
    So, i dl'ded it..and made a few adjustments (Because the current version...was kinda gay) so...like i said..i made a few adjustments...
    and i came up with this
    Code:
    Dim proxyenablecheck As Single
    Private Sub Form_Load()
    
    'Get Old Settings
    
     'Set Vars
     Dim Create
    
     'Get IE Registry Settings
     Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
     Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
     
     'Make read registry without extra modules
     Set Create = CreateObject("wscript.shell")
    
      'Set Old Setthings
      On Error Resume Next
      Text1.Text = Create.regread(ProxyServer)
      proxyenablecheck = Create.regread(ProxyEnable)
      
       Check1.Value = proxyenablecheck
       If proxyenablecheck = 1 Then
       Check1.Value = 1
       If proxyenablecheck = 0 Then
       Check1.Value = 0
       End If
       End If
      'Check if disable or enabled
      If Check1.Value = 0 Then
      Text1.Enabled = False
        Else
     If Check1.Value = 1 Then
     Text1.Enabled = True
     Else
        End If
         End If
       
       If Check1.Value = 0 Then
       lblProxyStatus.Caption = "Proxy Disabled" & lblProxyStatus.ForeColor = &HFF
       Else
       lblProxyStatus.Caption = "Proxy Enabled" & lblProxyStatus.ForeColor = &HFF00
       End If
       
    End Sub
    
    'Make Function
    Private Sub ProxySettings(Address As String, Enable As Integer)
     
     'If error go to errors
     On Error GoTo errors
     
     'Set Vars
     Dim Create
     Dim Key
     
     'Get IE Registry Settings
     Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
     Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
     
     'Make write registry without extra modules
     Set Create = CreateObject("wscript.shell")
    
    'Set Proxy Enabled Or Disable
    '1 = Enable
    '0 = Disable
    
       Key = ProxyEnable
       Create.RegWrite Key, Enable, "REG_DWORD"
    
    'Set Proxy Address And Port
    'Adress and Port go on same vaule
       Key = ProxyServer
       Create.RegWrite Key, Address, "REG_SZ"
       Exit Sub
       
       'Errors
    errors:
       MsgBox "Error!", vbCritical, "Error Found"
       
    End Sub
    
    Private Sub cmdChange_Click()
    
      'Change Settings
      ProxySettings Text1.Text, Check1.Value
    
      'Message box warning
      MsgBox "Exit all browsers to enable proxy changes.", vbExclamation, "Close Browsers"
    
    End Sub
    
    
    'Update if disable or enabled
    Private Sub check1_Change()
    
     On Error Resume Next
     
      If Check1.Value = 0 Then
      Text1.Enabled = False
        Else
     If Check1.Value = 1 Then
     Text1.Enabled = True
     Else
     If Text2.Text = "" Or " " Then
      Check1.Enabled = False
       End If
        End If
         End If
         
    End Sub
    (This code is an edited version..from..erm...http://www.pscode.com/vb/default.asp?lngWId=1 , so all most copyright to them (: )

    And, now it isnt working...- im new to vb...but, cant understand why this isnt working..
    Never usesd the registry before :'(
    Can you see what is wrong with it, anything obvious ?

    Thanks

  12. #12
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Quote Originally Posted by kingzl3y
    Can you see what is wrong with it, anything obvious ?
    Oh dear, where to start ? . Well, you AREN'T using "Option Explicit", and ARE using "On Error Resume Next". Between them, you WILL GET ERRORS WITHOUT ANY ERROR MESSAGES !!!!. I haven't time ATM to go through all the code (my son's coming out of hospital), but the following "Form_Load" code should give you ideas.
    vb Code:
    1. Option Explicit 'ALWAYS !!!!!!!
    2.  
    3. Dim ProxyEnableCheck As Integer
    4.  
    5. Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
    6. Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
    7.  
    8. Private Sub Form_Load()
    9.    Dim objCreate As Object
    10.    
    11.    Set objCreate = CreateObject("wscript.shell")
    12.  
    13. 'NEVER use "On Error Resume Next".
    14.    On Error GoTo ProxyServerError
    15.    Text1.Text = objCreate.regread(ProxyServer)
    16.    
    17.    On Error GoTo ProxyEnableError
    18.    Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
    19.  
    20. 'Check if disabled or enabled.
    21.    Select Case Check1.Value
    22.    Case 0 'Unticked.
    23.       Text1.Enabled = False
    24. 'Not sure what the following is supposed to be doing, but it WILL give an error for various reasons.
    25. '      lblProxyStatus.Caption = "Proxy Disabled" & lblProxyStatus.ForeColor = &HFF  '??????????
    26.    Case 1 'Ticked.
    27.       Text1.Enabled = True
    28. 'Same as above.....
    29. '      lblProxyStatus.Caption = "Proxy Enabled" & lblProxyStatus.ForeColor = &HFF00  '??????????
    30.    Case 2 'Greyed.
    31.       'Nothing to do.
    32.    End Select
    33.    
    34.    Exit Sub
    35. ProxyServerError:
    36. 'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    37.    MsgBox "Error reading registry value:- ProxyServer"
    38.    Resume Next
    39.    Exit Sub
    40. ProxyEnableError:
    41. 'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    42.    MsgBox "Error reading registry value:- ProxyEnable"
    43.    Resume Next
    44.    Exit Sub
    45. End Sub

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    ahhhh
    Yeah, sorry about that :x
    Im retarded when it comes to programming (: + In college we're learning vb.net..so using vb6 is a bit of a difference :P
    Any*****, sorry to hear about your son..(What ever it was) Hope he recovers (If he hasnt already)
    Okay, What does Option Explicit actually do x\
    Okay, i've edited it...and made took away the
    Code:
     Select Case Check1.Value
       Case 0 'Unticked.
          Text1.Enabled = False
    'Not sure what the following is supposed to be doing, but it WILL give an error for various reasons.
    lblProxyStatus.Caption = "Proxy Disabled" & lblProxyStatus.ForeColor = &HFF  '??????????
    And yes you was right, it gave me an error message xD
    Well, all that was supposed to be was a label, that when unticked (Proxy = off) it would say 'proxy Disabled' and be green.....however if it was ticked (Proxy = enabled) the label would say Proxy enabled and be red.
    But, i didnt think around the logic of it..i just started to mess around..with that...x[
    How else could it be done then?
    Thanks again,
    Really helpful

  14. #14
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Thanks for your thoughts on my son. He has Crohns disease - it's ongoing. Anyway...

    Option Explicit forces you to declare variables, ie "Dim MyVariable As Integer". If you don't specify it, VB will create a Variant type variable on the fly. This can cause probs if, say, a sub procedure expects an Integer to be passed to it - you get "Type Mismatch" error messages.

    Now I know what it's supposed to do (and the NET connection ), the line: "lblProxyStatus.Caption = "Proxy Disabled" & lblProxyStatus.ForeColor = &HFF" just needs to be split up. ie:

    Code:
    lblProxyStatus.Caption = "Proxy Disabled"
    lblProxyStatus.ForeColor = &HFF
    Next:

    In the sub "ProxySettings", you have
    Code:
    Dim Create
    Dim Key
    Because you haven't specified the type, VB will create Variants. You should really do: "Dim Create As Object". (I like to prefix variables with the type, makes things more readable:- "Dim objCreate As Object")

    The variable "Key" isn't needed, as you can do:
    Code:
    Create.RegWrite ProxyEnable, Enable, "REG_DWORD"
    and
    Code:
    Create.RegWrite ProxyServer, Address, "REG_SZ"
    Also, if you put the 2 registry key constants at the top of the module, as in my post above, you won't need to re-specify them in this sub.

    Finally:

    Private Sub Check1_Change() - could do with a re-write, using "Select Case Check1.Value" rather than a mishmash of "If's"

  15. #15
    New Member
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    10

    Re: Registry Manipulation ?

    Well I got it so far as to writing to the registry perfectly fine.

    I can read the information but parsing the data it reads from each individual key to a specific object (such as a text box) is a pain in the ass. That's where I need some guidance.

    Code:
    Private Sub QueryValue(sKeyName As String, sValueName As String)
    Dim lRetVal As Long         'result of the API functions
    Dim hKey As Long            'handle of opened key
    Dim vValue As Variant       'setting of queried value
    
    lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
                           KEY_QUERY_VALUE, hKey)
    lRetVal = QueryValueEx(hKey, sValueName, vValue)
    
    MsgBox vValue               'This pops up a message box for each key (currently 7 keys)
    RegCloseKey (hKey)
    End Sub
    This sub, obviously gets the keys(7). Now as you can see I used a message box just to see if the information displays correctly and it does. But 7 message boxes pop up one after another displaying the keys information.

    As I stated before I wanted to split the information being retrieved into different objects. So instead of a 'MsgBox' I could use this:

    For example: txtTextbox1.Text = vValue
    txtTextbox2.Text = vValue

    If I do it like this though, both of the text boxes will display the last key that is retrieved. I have tried using a 'Select Case' which didn't really work at all. I'm kind of tired and out of ideas :/

    P.S. Let's say I have two keys. One says "Hello" and the other says "World!"

    I want 'txtTextbot1.Text' to say "Hello" while the other says "World!"

    From:
    [HKEY_CURRENT_USER\Software\hsram\Application] 'String1' and 'String2' (for example)

    Any help would be appreciated.
    Last edited by hsram; Apr 15th, 2007 at 07:32 AM.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Oh..Never heard of that before :x
    Well, dunno what to say..except goodluck, hope there one day is a cure

    Anyway back to business, i've took what you've said into consideration
    and now, i've came up with this :
    Code:
          Option Explicit 'ALWAYS !!!!!!!
          Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
          Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
          Private Sub Form_Load()
             Dim objCreate As Object
             Set objCreate = CreateObject("wscript.shell")
          'NEVER use "On Error Resume Next".
             On Error GoTo ProxyServerError
             Text1.Text = objCreate.regread(ProxyServer)
             On Error GoTo ProxyEnableError
             Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
                Select Case Check1.Value
                Case 0
                lblProxyStatus.Caption = "Proxy Disabled"
              lblProxyStatus.ForeColor = &HFF
             Case 1
              lblProxyStatus.Caption = "Proxy Enabled"
              lblProxyStatus.ForeColor = &HFF00
           End Select
                  Exit Sub
    ProxyServerError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyServer"
             Resume Next
             Exit Sub
    ProxyEnableError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyEnable"
             Resume Next
             Exit Sub
          End Sub
    It works perfectly
    However
    When i enable the proxy (Via IE settings) i run the app' and it errors on ' ProxyEnableError:'
    But, if i take away (Or make it a comment) the
    Code:
             Case 1
              lblProxyStatus.Caption = "Proxy Enabled"
             ' lblProxyStatus.ForeColor = &HFF00
    It works :S
    but if i take away the ' ...it erros on me
    but if i disable the proxy and then run it..it runs fine..and says Proxy disabled..and is in green

    Any ideas?

    (I'd rather cover this first then start on writing to the registry)
    If' thats ok with you though
    Thanks again xx

    *if that makes any sense :S*

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Quote Originally Posted by hsram
    Well I got it so far as to writing to the registry perfectly fine.

    I can read the information but parsing the data it reads from each individual key to a specific object (such as a text box) is a pain in the ass. That's where I need some guidance.

    Code:
    Private Sub QueryValue(sKeyName As String, sValueName As String)
    Dim lRetVal As Long         'result of the API functions
    Dim hKey As Long            'handle of opened key
    Dim vValue As Variant       'setting of queried value
    
    lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
                           KEY_QUERY_VALUE, hKey)
    lRetVal = QueryValueEx(hKey, sValueName, vValue)
    
    MsgBox vValue               'This pops up a message box for each key (currently 7 keys)
    RegCloseKey (hKey)
    End Sub
    This sub, obviously gets the keys(7). Now as you can see I used a message box just to see if the information displays correctly and it does. But 7 message boxes pop up one after another displaying the keys information.

    As I stated before I wanted to split the information being retrieved into different objects. So instead of a 'MsgBox' I could use this:

    For example: txtTextbox1.Text = vValue
    txtTextbox2.Text = vValue

    If I do it like this though, both of the text boxes will display the last key that is retrieved. I have tried using a 'Select Case' which didn't really work at all. I'm kind of tired and out of ideas :/

    P.S. Let's say I have two keys. One says "Hello" and the other says "World!"

    I want 'txtTextbot1.Text' to say "Hello" while the other says "World!"

    From:
    [HKEY_CURRENT_USER\Software\hsram\Application] 'String1' and 'String2' (for example)

    Any help would be appreciated.
    Oi, get your own topic :P

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    ok
    ignore my last post
    i dunno what it was :S but now its fixed (i think it was the the colour code'in for the enabled...ahwell..i changed it now)

    Ok, without that error..i got this far...
    Code:
          Option Explicit 'ALWAYS !!!!!!!
          Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
          Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
    
    
    
          Private Sub Form_Load()
             Dim objCreate As Object
             Set objCreate = CreateObject("wscript.shell")
          'NEVER use "On Error Resume Next".
             On Error GoTo ProxyServerError
             Text1.Text = objCreate.regread(ProxyServer)
             On Error GoTo ProxyEnableError
             Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
                Select Case Check1.Value
                Case 0
                lblProxyStatus.Caption = "Proxy Disabled"
              lblProxyStatus.ForeColor = &HFF
              Text1.Enabled = False
             Case 1
              lblProxyStatus.Caption = "Proxy Enabled"
              lblProxyStatus.ForeColor = &HFF00&
              Text1.Enabled = True
                     End Select
                  Exit Sub
    ProxyServerError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyServer"
             Resume Next
             Exit Sub
    ProxyEnableError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyEnable"
             Resume Next
             Exit Sub
          End Sub
    
    Private Sub Cmdchange_Click()
    Select Case Check1.Value
        Case 0
              lblProxyStatus.Caption = "Proxy Disabled"
              lblProxyStatus.ForeColor = &HFF
              Text1.Enabled = False
       Case 1
              lblProxyStatus.Caption = "Proxy Enabled"
              lblProxyStatus.ForeColor = &HFF00&
              Text1.Enabled = True
              End Select
        
    End Sub
    Now, how do i save what the value of the checkbox is (either on or off..0 or 1....etc)

  19. #19
    New Member
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    10

    Re: Registry Manipulation ?

    Quote Originally Posted by kingzl3y
    ok
    ignore my last post
    i dunno what it was :S but now its fixed (i think it was the the colour code'in for the enabled...ahwell..i changed it now)

    Ok, without that error..i got this far...
    Code:
          Option Explicit 'ALWAYS !!!!!!!
          Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
          Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
    
    
    
          Private Sub Form_Load()
             Dim objCreate As Object
             Set objCreate = CreateObject("wscript.shell")
          'NEVER use "On Error Resume Next".
             On Error GoTo ProxyServerError
             Text1.Text = objCreate.regread(ProxyServer)
             On Error GoTo ProxyEnableError
             Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
                Select Case Check1.Value
                Case 0
                lblProxyStatus.Caption = "Proxy Disabled"
              lblProxyStatus.ForeColor = &HFF
              Text1.Enabled = False
             Case 1
              lblProxyStatus.Caption = "Proxy Enabled"
              lblProxyStatus.ForeColor = &HFF00&
              Text1.Enabled = True
                     End Select
                  Exit Sub
    ProxyServerError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyServer"
             Resume Next
             Exit Sub
    ProxyEnableError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyEnable"
             Resume Next
             Exit Sub
          End Sub
    
    Private Sub Cmdchange_Click()
    Select Case Check1.Value
        Case 0
              lblProxyStatus.Caption = "Proxy Disabled"
              lblProxyStatus.ForeColor = &HFF
              Text1.Enabled = False
       Case 1
              lblProxyStatus.Caption = "Proxy Enabled"
              lblProxyStatus.ForeColor = &HFF00&
              Text1.Enabled = True
              End Select
        
    End Sub
    Now, how do i save what the value of the checkbox is (either on or off..0 or 1....etc)
    If CHECKBOX.Value = 1 Or CHECKBOX.Value = 0 Then
    SAVE
    End If

    - OR -

    If CHECKBOX = vbChecked Then
    SAVE
    Else
    SAVE
    End If

  20. #20
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Your save code "Private Sub ProxySettings(Address As String, Enable As Integer)" is more or less right, it just wants simplifying as per my last post, and some more suitable error messaging - eg:
    vb Code:
    1. Private Sub ProxySettings(Address As String, Enable As Integer)
    2.    Dim objCreate As Object
    3.  
    4.    Set objCreate = CreateObject("wscript.shell")
    5.    
    6. 'On Error etc... - similar to that in Form_Load.
    7.    objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
    8.    
    9. 'On Error etc... - similar to that in Form_Load.
    10.    objCreate.RegWrite ProxyServer, Address, "REG_SZ"
    11.    
    12.    Exit Sub
    13. SaveError:
    14.    
    15. 'Suitable error messaging here - similar to that in Form_Load.
    16.  
    17. 'MsgBox "Error!", vbCritical, "Error Found"
    18.  
    19. End Sub
    You'll need to put the call "ProxySettings Text1.Text, Check1.Value" in the "Check1_Click()" and probably the click event of a "save changes" command button. And optionally the "Form_Unload" event if you want to save the changes on exit.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Firstly,
    Schoolbusdriver i fawking love you xD ( )

    Well, i've took what you've wrote into consideration and came up with this :

    vb Code:
    1. Option Explicit 'ALWAYS !!!!!!!
    2.       Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
    3.       Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
    4.       Private Sub Form_Load()
    5.          Dim objCreate As Object
    6.          Set objCreate = CreateObject("wscript.shell")
    7.       'NEVER use "On Error Resume Next".
    8.          On Error GoTo ProxyServerError
    9.          Text1.Text = objCreate.regread(ProxyServer)
    10.          On Error GoTo ProxyEnableError
    11.          Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
    12.             Select Case Check1.Value
    13.             Case 0
    14.             txtProxyStatus.Text = "Proxy Disabled"
    15.             txtProxyStatus.BackColor = &HFF
    16.           Text1.Enabled = False
    17.          Case 1
    18.           txtProxyStatus.Text = "Proxy Enabled"
    19.             txtProxyStatus.BackColor = &HFF00&
    20.           Text1.Enabled = True
    21.                  End Select
    22.               Exit Sub
    23. ProxyServerError:
    24.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    25.          MsgBox "Error reading registry value:- ProxyServer"
    26.          Resume Next
    27.          Exit Sub
    28. ProxyEnableError:
    29.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    30.          MsgBox "Error reading registry value:- ProxyEnable"
    31.          Resume Next
    32.          Exit Sub
    33.       End Sub
    34. Private Sub Cmdchange_Click()
    35. ProxySettings Text1.Text, Check1.Value
    36. Select Case Check1.Value
    37.     Case 0
    38.             txtProxyStatus.Text = "Proxy Disabled"
    39.             txtProxyStatus.BackColor = &HFF
    40.           Text1.Enabled = False
    41.     Case 1
    42.           txtProxyStatus.Text = "Proxy Enabled"
    43.             txtProxyStatus.BackColor = &HFF00&
    44.           Text1.Enabled = True
    45.           End Select
    46.           MsgBox "For settings to take affect, Please re-start Internet Explorer", vbOKOnly, "Restart IE"
    47.     End Sub
    48.       Private Sub ProxySettings(Address As String, Enable As Integer)
    49.          Dim objCreate As Object
    50.          Set objCreate = CreateObject("wscript.shell")
    51.          On Error GoTo ProxyServerWriteError
    52.          objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
    53.          On Error GoTo ProxyEnableWriteError
    54.          objCreate.RegWrite ProxyServer, Address, "REG_SZ"
    55.    Exit Sub
    56. ProxyServerWriteError:
    57.             MsgBox "Error saving Proxy server", vbCritical, "Error!"
    58. ProxyEnableWriteError:
    59.             MsgBox "Error saving Proxy status", vbCritical, "Error!"
    60.       End Sub
    61. Private Sub Text1_Click()
    62. MsgBox "Format = Address:Port", vbInformation, "Please use correct format"
    63. End Sub

    Now, to what do you actually mean, but the form_unload part :x

    Btw, are the Errormessages and errorchecking anygood & yes, i will comment on the finish product (:
    and...here is my GUI
    what'd you think (Took me 3 mins :< so dont laugh!)


    Kankerflecken.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    And aswell.
    I'm thinking about adding some more functionality (is that a word o_0)
    Basically, my idea is - to have a backup button(or whatever) which will initially backup the proxyserver address and save it to the registry, (However using Darkbobs code
    vb Code:
    1. Save a text string:
    2. Text$="Stuff to Save"
    3. SaveSetting "MyProgram", "MySection", "TextValue1", Text$
    4.  
    5. Get your strng back
    6. Text$= GetSetting("MyProgram", "MySection", "TextValue1", Default:="")
    And then, if the user has an error or what ever, they can 'restore' the original address.
    Understand me?
    is that a good idea? or basically a waste of time
    Kankerflecken.

  23. #23
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Quote Originally Posted by kingzl3y
    (Took me 3 mins :< so dont laugh!)
    So you made a cup of tea in that time as well ??

    One thing I fogot to mention, the Check1_Click() event will fire when the form loads - whether you like it or not (it's a VB bug). If you're going to put code in "Check1_Click", add
    vb Code:
    1. Dim AllowEvents As Boolean
    to the declarations section of the form, and
    vb Code:
    1. Private Sub Form_Initialize()
    2.    AllowEvents = False
    3. End Sub
    and
    vb Code:
    1. If AllowEvents = False Then Exit Sub
    as the first line in "Check1_Click", to prevent false triggering, and
    vb Code:
    1. AllowEvents = True
    as the last line before "Exit Sub" and the error handling in "Form_Load".

    Saving the original settings is always a good idea, and using Save/GetSetting is ideal as it stores to a seperate part of the registry. To make sure the original saved settings aren't overwritten, you also need to save a "flag" indicating that the prog has already been run at least once. Not so sure about putting a seperate "Save as Defaults" button on the form - it tempts an end user to click it [by mistake ] which defeats the object.... A better way is to make it automatic. Of course a "Restore Originals" will be necessary...

    So... the last line before "Exit Sub" and the error handling in "Form_Load" could be
    vb Code:
    1. FirstRunCheck
    then add a sub...
    vb Code:
    1. Public Sub FirstRunCheck()
    2.    Dim strHasItRunBefore As String
    3.    
    4. 'If the value doesn't exist, will return "0"
    5.    strHasItRunBefore = GetSetting(App.EXEName, "FirstRun", "RunFlag", "0")
    6.    
    7.    If strHasItRunBefore = "0" Then
    8.  
    9. 'So... this IS the first run, - change the flag to "1".
    10.    SaveSetting App.EXEName, "FirstRun", "RunFlag", "1"
    11.  
    12. 'Save other settings code here...
    13.    SaveSetting App.EXEName, "Settings", "ProxyServer", txtProxyStatus.Text
    14.  
    15. 'Similar for the CheckBox, and any other settings...
    16. '------------
    17. '------------
    18. '------------
    19. '------------
    20.    End If
    21. End Sub
    Restoring the defaults would simply be a case of using GetSetting to change the values of the textbox etc and calling "Cmdchange_Click".

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Nawh, no tea - Kettle is downstairs..and the time it takes to boil, would run over 3 mins :P
    Anyway.
    Ok, the code you provide - Kinda confused me...(Proberly my fault.. ._. )
    So, if you can look at this and check if it is correct.
    (Ill BOLD the code i added - just check if it is in the right place)
    Code:
          Option Explicit 'ALWAYS !!!!!!!
          Dim AllowEvents As Boolean
          Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
          Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
          Private Sub Form_Initialize()
             AllowEvents = False
          End Sub
    Private Sub Check1_Click()
    If AllowEvents = False Then Exit Sub
    End Sub
          Private Sub Form_Load()
                  Dim objCreate As Object
             Set objCreate = CreateObject("wscript.shell")
          'NEVER use "On Error Resume Next".
             On Error GoTo ProxyServerError
             Text1.Text = objCreate.regread(ProxyServer)
             On Error GoTo ProxyEnableError
             Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
                Select Case Check1.Value
                Case 0
                txtProxyStatus.Text = "Proxy Disabled"
                txtProxyStatus.BackColor = &HFF
              Text1.Enabled = False
             Case 1
              txtProxyStatus.Text = "Proxy Enabled"
                txtProxyStatus.BackColor = &HFF00&
              Text1.Enabled = True
                     End Select
                     AllowEvents = True
                  Exit Sub
    ProxyServerError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyServer"
             Resume Next
             Exit Sub
    ProxyEnableError:
          'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
             MsgBox "Error reading registry value:- ProxyEnable"
             Resume Next
             Exit Sub
          End Sub
    Private Sub Cmdchange_Click()
    ProxySettings Text1.Text, Check1.Value
    Select Case Check1.Value
        Case 0
                txtProxyStatus.Text = "Proxy Disabled"
                txtProxyStatus.BackColor = &HFF
              Text1.Enabled = False
        Case 1
              txtProxyStatus.Text = "Proxy Enabled"
                txtProxyStatus.BackColor = &HFF00&
              Text1.Enabled = True
              End Select
              MsgBox "For settings to take affect, Please re-start Internet Explorer", vbOKOnly, "Restart IE"
        End Sub
          Private Sub ProxySettings(Address As String, Enable As Integer)
             Dim objCreate As Object
             Set objCreate = CreateObject("wscript.shell")
             On Error GoTo ProxyServerWriteError
             objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
             On Error GoTo ProxyEnableWriteError
             objCreate.RegWrite ProxyServer, Address, "REG_SZ"
       Exit Sub
    ProxyServerWriteError:
                MsgBox "Error saving Proxy server", vbCritical, "Error!"
    ProxyEnableWriteError:
                MsgBox "Error saving Proxy status", vbCritical, "Error!"
          End Sub
    Private Sub Text1_Click()
    MsgBox "Format = Address:Port", vbInformation, "Please use correct format"
    End Sub
    I actually understand what thats doing-quite easy actually.

    Okay, so if thats all in order - i'll start with the 2nd Part (Backup registry)

    Thanks again mate.
    Btw, you're English right?
    Kankerflecken.

  25. #25
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Yep, that looks ok.

    Quote Originally Posted by kingzl3y
    Btw, you're English right?
    I most certainly am.

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Awh awesome!
    you are! Sweet!
    Its actually nice to have a person the same nationality helping me - instead of some kid -5 hours behind..and someone who actually know what a brew is!
    ...Back to the code

    I get a type mismatch when i added the
    vb Code:
    1. Public Sub FirstRunCheck()
    2.          Dim strHasItRunBefore As String
    3.     'If the value doesn't exist, will return "0"
    4.          strHasItRunBefore = GetSetting(Pr0xytool, "FirstRun", "RunFlag", "0")
    5.          If strHasItRunBefore = "0" Then
    6.       'So... this IS the first run, - change the flag to "1".
    7.          SaveSetting Pr0xytool, "FirstRun", "RunFlag", "1"
    8.       'Save other settings code here...
    9.          SaveSetting Pr0xytool, "Settings", "ProxyServer", txtProxyStatus.Text
    10.       'Similar for the CheckBox, and any other settings...
    11.       '------------
    12.       '-----------
    13.       '------------
    14.       '------------
    15.          End If
    16.       End Sub

    It highlights (in yellow)
    Public Sub FirstRunCheck()

    and then (in grey)
    SaveSetting

    Btw, where abouts you live? Ever heard of Tamworth? (:
    Thanks again!
    Kankerflecken.

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Aswell, i've found a way to implement the restore function..(well where to but the button for it)
    well, instead of having a button - have a menu (God, don't VB6 menu's suck ess ._. )
    e.g.


    and then having
    vb Code:
    1. Private Sub menuExit_Click()
    2. Unload Me ' exit app
    3. End Sub
    4. Private Sub menuRestore_Click()
    5. 'Restore original Settings
    6. End Sub

    Think thats a better idea, then having an additional button?
    Kankerflecken.

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    ROAR!
    I think i have Cracked it!
    Not sure, why your code was not working
    However, i (after having a while to think about it)
    Came up with this:

    vb Code:
    1. FirstRuncheck
    In the Form_load

    vb Code:
    1. Public Sub FirstRuncheck()
    2.  
    3. Dim strRanbefore As String
    4.         On Error GoTo GetError
    5.        strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0")
    6.            If strRanbefore = 0 Then
    7.            On Error GoTo SaveError
    8.         SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
    9.            SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text
    10.            End If
    11.            Exit Sub
    12. GetError:
    13.           MsgBox ("Error checking if program has ran before")
    14.            Exit Sub
    15. SaveError:
    16.         MsgBox ("Error Saving Firstrun status")
    17.            Exit Sub
    18.            End Sub

    I think that works perfecly! (Ill let you decide weather(ffs, i never know how to spell the other 'weather' properly ><) :P

    However, when i come to restore the code - it doesnt work...
    I've tried to think about it..but i cannot...my brain has had enough for today
    Stupid
    NRZI and manchester Encoding ARRRRRRRRRRRRRRRRR
    Stupid college!

    this is my code
    vb Code:
    1. Private Sub menuRestore_Click()
    2. txtProxyAddress = GetSetting("Pr0xytool", "Settings", "Proxyserver")
    3. End Sub

    I know its something to do with the 'txtproxyaddress' part - but i cant thinkwhat to put there, i cant put 'ProxyServer' Becuase that is a const value
    so im all bummed out

    Kankerflecken.

  29. #29
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    Sorry about the delay - been a busy few days. Are you absolutely sure it's not working ? To test it, clear the textbox first:

    vb Code:
    1. Private Sub menuRestore_Click()
    2.    txtProxyAddress.Text = "" '<------
    3.    txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver")
    4. End Sub

    Also, if IE isn't set to use a proxy server, the registry value name "ProxyServer" may not be there, and "ProxyEnable" will be set to 0.

    BTW, Staffordshire sounds nice - I live in Oldham (The pimple on the anus of England )

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Ah thank god!
    I was getting worried ._. =]
    Anyway
    Yes, sorry i actually think it was working - I just didnt realised...i think i was actually seeing things that night anyway x|
    Anyway, i've added your code and i must admit it works perfectly :]

    BUT (i hate buts ><")
    What you said, i investigated
    I went in to CP > Internet settings > changed the proxy server address to
    "" : "" (So basically blank,
    when i ran my app, it error'd " Error reading registry value:- ProxyServer"

    So, would i need to wack in an if statement
    vb Code:
    1. If Proxyserver = ""
    2. then
    3. 'whatever, i cannot think what to put ><"
    4. end if

    Would that work? or how would i get around it ?


    AHA, Staffordshire sucks ass - i wanan live abroad! im sick on England
    I hate my peers - Drugs, Drink, Antisocial etc - Pathetic.
    Kankerflecken.

  31. #31
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    At this point you could (in Form_Load):-
    vb Code:
    1. 'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    to get rid of the registry reading errors that the scripting host raises - if you're happy that it's working the way you want it to. (Normally I wouldn't advocate using "Resume Next", but this is one of those rare exceptions)

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Uhuhm, what do you mean, comment out the message box? :x
    Kankerflecken.

  33. #33
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    In the error handler in Form_Load:-
    vb Code:
    1. ProxyServerError:
    2. 'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    3. '   MsgBox "Error reading registry value:- ProxyServer"
    4.    Resume Next
    5. '   Exit Sub
    6. ProxyEnableError:
    7. 'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    8. '   MsgBox "Error reading registry value:- ProxyEnable"
    9.    Resume Next
    10. '   Exit Sub
    11. End Sub
    Leave "Resume Next" uncommented so that the rest of the code runs.

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    Dude, to be honest
    i think thats it

    I've kinda commented

    anychance of one last look, if its all a'okay then ill make this mofo'in thread resolved with a capital C

    vb Code:
    1. '*******************
    2. 'Author: Kingzl3y
    3. 'Name: Proxy tool
    4. 'Description: Enable/Disable and edit proxy address
    5. 'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
    6. 'Have fun
    7. 'Website - Coming soon.
    8. '*******************
    9.       Option Explicit 'ALWAYS !!!!!!!
    10.       Dim AllowEvents As Boolean ' Define AllowEvens as boolean
    11.       Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
    12.       Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
    13.       Private Sub Form_Initialize()
    14.          AllowEvents = False
    15.       End Sub
    16. Private Sub Check1_Click()
    17. If AllowEvents = False Then Exit Sub
    18. End Sub
    19.       Private Sub Form_Load()
    20.               Dim objCreate As Object
    21.          Set objCreate = CreateObject("wscript.shell")
    22.       'NEVER use "On Error Resume Next".
    23.          On Error GoTo ProxyServerError
    24.      txtProxyAddress = objCreate.regread(ProxyServer)
    25.          On Error GoTo ProxyEnableError
    26.          Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
    27.             Select Case Check1.Value
    28.             Case 0
    29.             txtProxyStatus.Text = "Proxy Disabled"
    30.             txtProxyStatus.BackColor = &HFF
    31.           txtProxyAddress.Enabled = False
    32.          Case 1
    33.           txtProxyStatus.Text = "Proxy Enabled"
    34.             txtProxyStatus.BackColor = &HFF00&
    35.           txtProxyAddress.Enabled = True
    36.                  End Select
    37.                  AllowEvents = True
    38.  FirstRuncheck
    39.               Exit Sub
    40. ProxyServerError:
    41.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    42.       '   MsgBox "Error reading registry value:- ProxyServer"
    43.          Resume Next
    44.       '   Exit Sub
    45. ProxyEnableError:
    46.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    47.       '   MsgBox "Error reading registry value:- ProxyEnable"
    48.          Resume Next
    49.       '   Exit Sub
    50.       End Sub
    51. Private Sub Cmdchange_Click()
    52. ProxySettings txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
    53. Select Case Check1.Value
    54.     Case 0 ' if proxy is disabled then
    55.             txtProxyStatus.Text = "Proxy Disabled"
    56.             txtProxyStatus.BackColor = &HFF
    57.           txtProxyAddress.Enabled = False
    58.     Case 1 ' if proxy is enabled then
    59.           txtProxyStatus.Text = "Proxy Enabled"
    60.             txtProxyStatus.BackColor = &HFF00&
    61.           txtProxyAddress.Enabled = True
    62.           End Select
    63.           MsgBox "For settings to take affect, Please re-start Internet Explorer", vbOKOnly, "Restart IE"
    64.     End Sub
    65.       Private Sub ProxySettings(Address As String, Enable As Integer)
    66.          Dim objCreate As Object
    67.          Set objCreate = CreateObject("wscript.shell")
    68.          On Error GoTo ProxyServerWriteError
    69.          objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
    70.          On Error GoTo ProxyEnableWriteError
    71.          objCreate.RegWrite ProxyServer, Address, "REG_SZ"
    72.    Exit Sub
    73. ProxyServerWriteError:
    74.             MsgBox "Error saving Proxy server", vbCritical, "Error!"
    75. ProxyEnableWriteError:
    76.             MsgBox "Error saving Proxy status", vbCritical, "Error!"
    77.       End Sub
    78. Private Sub menuExit_Click()
    79. Unload Me
    80. End Sub
    81.       Private Sub menuRestore_Click()
    82.          txtProxyAddress.Text = "" '<------
    83.          txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
    84.          MsgBox "Original Settings restored - " & txtProxyAddress.Text
    85.       End Sub
    86. Public Sub FirstRuncheck()
    87. Dim strRanbefore As String
    88.         On Error GoTo GetError
    89.        strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
    90.            If strRanbefore = 0 Then
    91.            On Error GoTo SaveError
    92.         SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
    93.            SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
    94.            End If
    95.            Exit Sub
    96. GetError:
    97.           MsgBox ("Error checking if program has ran before")
    98.            Exit Sub
    99. SaveError:
    100.         MsgBox ("Error Saving Firstrun status")
    101.            Exit Sub
    102.            End Sub
    103.  
    104. Private Sub Text1_Click()
    105. MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
    106. End Sub

    Kankerflecken.

  35. #35
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    The only things I can see that need doing are: In "Public Sub FirstRuncheck()" you need to save the setting (value) of the CheckBox, and of course restore it in "Private Sub menuRestore_Click()". (Just use the same method as you have there for the textbox). Then you've done

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    hey mate, Sorry i've been a bit busy
    Okay, i dont what you suggested
    However i have a wee' problem,
    When the program first runs, it saves the status and addrees perfectly,
    However when i go to restore it doesnt really restore, it just puts the saved settings in the txtbox...it doesnt really save them save them..same as the checkbox, that will become ticked, however it will still be off (Or on...visa versa)

    Heres my code so fare
    vb Code:
    1. '*******************
    2. 'Author: Kingzl3y
    3. 'Name: Proxy tool
    4. 'Description: Enable/Disable and edit proxy address
    5. 'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
    6. 'Have fun
    7. 'Website - Coming soon.
    8. '*******************
    9.       Option Explicit 'ALWAYS !!!!!!!
    10.       Dim AllowEvents As Boolean ' Define AllowEvens as boolean
    11.       Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
    12.       Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
    13.       Private Sub Form_Initialize()
    14.          AllowEvents = False
    15.       End Sub
    16. Private Sub Check1_Click()
    17. If AllowEvents = False Then Exit Sub
    18. End Sub
    19.       Private Sub Form_Load()
    20.               Dim objCreate As Object
    21.          Set objCreate = CreateObject("wscript.shell")
    22.       'NEVER use "On Error Resume Next".
    23.          On Error GoTo ProxyServerError
    24.      txtProxyAddress = objCreate.regread(ProxyServer)
    25.          On Error GoTo ProxyEnableError
    26.          Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
    27.             Select Case Check1.Value
    28.             Case 0
    29.             txtProxyStatus.Text = "Proxy Disabled"
    30.             txtProxyStatus.BackColor = &HFF
    31.           txtProxyAddress.Enabled = False
    32.          Case 1
    33.           txtProxyStatus.Text = "Proxy Enabled"
    34.             txtProxyStatus.BackColor = &HFF00&
    35.           txtProxyAddress.Enabled = True
    36.                  End Select
    37.                  AllowEvents = True
    38.  FirstRuncheck
    39.               Exit Sub
    40. ProxyServerError:
    41.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    42.       '   MsgBox "Error reading registry value:- ProxyServer"
    43.          Resume Next
    44.       '   Exit Sub
    45. ProxyEnableError:
    46.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    47.       '   MsgBox "Error reading registry value:- ProxyEnable"
    48.          Resume Next
    49.       '   Exit Sub
    50.       End Sub
    51. Private Sub Cmdchange_Click()
    52. ProxySettings txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
    53. Select Case Check1.Value
    54.     Case 0 ' if proxy is disabled then
    55.             txtProxyStatus.Text = "Proxy Disabled"
    56.             txtProxyStatus.BackColor = &HFF&
    57.             txtProxyAddress.Enabled = False
    58.     Case 1 ' if proxy is enabled then
    59.             txtProxyStatus.Text = "Proxy Enabled"
    60.             txtProxyStatus.BackColor = &HFF00&
    61.             txtProxyAddress.Enabled = True
    62.           End Select
    63.           MsgBox "For settings to take affect, Please re-start Internet Explorer", vbOKOnly, "Restart IE"
    64.     End Sub
    65.       Private Sub ProxySettings(Address As String, Enable As Integer)
    66.          Dim objCreate As Object
    67.          Set objCreate = CreateObject("wscript.shell")
    68.          On Error GoTo ProxyServerWriteError
    69.          objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
    70.          On Error GoTo ProxyEnableWriteError
    71.          objCreate.RegWrite ProxyServer, Address, "REG_SZ"
    72.    Exit Sub
    73. ProxyServerWriteError:
    74.             MsgBox "Error saving Proxy server", vbCritical, "Error!"
    75. ProxyEnableWriteError:
    76.             MsgBox "Error saving Proxy status", vbCritical, "Error!"
    77.       End Sub
    78. Private Sub menuExit_Click()
    79. Unload Me
    80. End Sub
    81.       Private Sub menuRestore_Click()
    82.          txtProxyAddress.Text = "" '<------
    83.          txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
    84.          Check1.Value = GetSetting("pr0xytool", "Settings", "Proxystatus", 0)  ' Restore original proxy status (on/off)
    85.          MsgBox "Original Settings restored - " & txtProxyAddress.Text & vbNewLine & " Proxy Enabled - " & Check1.Value
    86.       End Sub
    87. Public Sub FirstRuncheck()
    88. Dim strRanbefore As String
    89.         On Error GoTo GetError
    90.        strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
    91.            If strRanbefore = 0 Then
    92.            On Error GoTo SaveError
    93.         SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
    94.            SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
    95.            SaveSetting "Pr0xytool", "Settings", "ProxyStatus", CInt(Check1.Value) ' saves proxy status (on/off)
    96.            End If
    97.            Exit Sub
    98. GetError:
    99.           MsgBox ("Error checking if program has ran before")
    100.            Exit Sub
    101. SaveError:
    102.         MsgBox ("Error Saving Firstrun status")
    103.            Exit Sub
    104.            End Sub
    105.  
    106. Private Sub Text1_Click()
    107. MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
    108. End Sub

    Kankerflecken.

  37. #37

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    AHWEHWEHWEHWH
    Dude, i think i've done it
    and it seems to work perfectly!

    Once last look

    vb Code:
    1. '*******************
    2. 'Author: Kingzl3y
    3. 'Name: Proxy tool
    4. 'Description: Enable/Disable and edit proxy address
    5. 'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
    6. 'Have fun
    7. 'Website - Coming soon.
    8. '*******************
    9.       Option Explicit 'ALWAYS !!!!!!!
    10.       Dim AllowEvents As Boolean ' Define AllowEvens as boolean
    11.       Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
    12.       Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
    13.      
    14.       Private Sub Form_Initialize()
    15.          AllowEvents = False
    16.         End Sub
    17.        
    18.        
    19. Private Sub Check1_Click()
    20. If AllowEvents = False Then Exit Sub
    21. Select Case Check1.Value
    22.     Case 0 ' if proxy is disabled then
    23.             txtProxyStatus.Text = "Proxy Disabled"
    24.             txtProxyStatus.BackColor = &HFF&
    25.             txtProxyAddress.Enabled = False
    26.     Case 1 ' if proxy is enabled then
    27.             txtProxyStatus.Text = "Proxy Enabled"
    28.             txtProxyStatus.BackColor = &HFF00&
    29.             txtProxyAddress.Enabled = True
    30.           End Select
    31. End Sub
    32.  
    33.       Private Sub Form_Load()
    34.               Dim objCreate As Object
    35.          Set objCreate = CreateObject("wscript.shell")
    36.       'NEVER use "On Error Resume Next".
    37.          On Error GoTo ProxyServerError
    38.      txtProxyAddress = objCreate.regread(ProxyServer)
    39.          On Error GoTo ProxyEnableError
    40.          Check1.Value = CInt(objCreate.regread(ProxyEnable)) 'Stored as DWORD. Convert to integer.
    41.             Select Case Check1.Value
    42.             Case 0
    43.             txtProxyStatus.Text = "Proxy Disabled"
    44.             txtProxyStatus.BackColor = &HFF
    45.           txtProxyAddress.Enabled = False
    46.          Case 1
    47.           txtProxyStatus.Text = "Proxy Enabled"
    48.             txtProxyStatus.BackColor = &HFF00&
    49.           txtProxyAddress.Enabled = True
    50.                  End Select
    51.                  AllowEvents = True
    52.  FirstRuncheck
    53.               Exit Sub
    54. ProxyServerError:
    55.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    56.       '   MsgBox "Error reading registry value:- ProxyServer"
    57.          Resume Next
    58.       '   Exit Sub
    59. ProxyEnableError:
    60.       'Comment out the message box, if required, AFTER the app is FULLY DEBUGGED!.
    61.       '   MsgBox "Error reading registry value:- ProxyEnable"
    62.          Resume Next
    63.       '   Exit Sub
    64.       End Sub
    65.      
    66. Private Sub Cmdchange_Click()
    67. ProxySettings txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
    68.  
    69. Select Case Check1.Value
    70.     Case 0 ' if proxy is disabled then
    71.             txtProxyStatus.Text = "Proxy Disabled"
    72.             txtProxyStatus.BackColor = &HFF&
    73.             txtProxyAddress.Enabled = False
    74.     Case 1 ' if proxy is enabled then
    75.             txtProxyStatus.Text = "Proxy Enabled"
    76.             txtProxyStatus.BackColor = &HFF00&
    77.             txtProxyAddress.Enabled = True
    78.           End Select
    79.           MsgBox "For settings to take affect, Please re-start Internet Explorer", vbOKOnly, "Restart IE"
    80.     End Sub
    81.    
    82.       Private Sub ProxySettings(Address As String, Enable As Integer)
    83.          Dim objCreate As Object
    84.          Set objCreate = CreateObject("wscript.shell")
    85.          On Error GoTo ProxyServerWriteError
    86.          objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
    87.          On Error GoTo ProxyEnableWriteError
    88.          objCreate.RegWrite ProxyServer, Address, "REG_SZ"
    89.    Exit Sub
    90. ProxyServerWriteError:
    91.             MsgBox "Error saving Proxy server", vbCritical, "Error!"
    92. ProxyEnableWriteError:
    93.             MsgBox "Error saving Proxy status", vbCritical, "Error!"
    94.       End Sub
    95.      
    96. Private Sub menuExit_Click()
    97. Unload Me
    98. End Sub
    99.  
    100.       Private Sub menuRestore_Click()
    101.          txtProxyAddress.Text = "" '<------
    102.          txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
    103.          Check1.Value = GetSetting("pr0xytool", "Settings", "Proxystatus", 0)  ' Restore original proxy status (on/off)
    104.          ProxySettings txtProxyAddress, Check1.Value ' Save restored settings to main registry
    105.          MsgBox "Original Settings restored - " & txtProxyAddress.Text & vbNewLine & " Proxy Enabled - " & Check1.Value
    106.       End Sub
    107.      
    108. Public Sub FirstRuncheck()
    109. Dim strRanbefore As String
    110.         On Error GoTo GetError
    111.        strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
    112.            If strRanbefore = 0 Then
    113.            On Error GoTo SaveError
    114.         SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
    115.            SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
    116.            SaveSetting "Pr0xytool", "Settings", "ProxyStatus", CInt(Check1.Value) ' saves proxy status (on/off)
    117.            End If
    118.            Exit Sub
    119. GetError:
    120.           MsgBox ("Error checking if program has ran before")
    121.            Exit Sub
    122. SaveError:
    123.         MsgBox ("Error Saving Firstrun status")
    124.            Exit Sub
    125.            End Sub
    126.            
    127.  
    128. Private Sub txtProxyAddress_Click()
    129. MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
    130. End Sub

    gui @

    Kankerflecken.

  38. #38
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Registry Manipulation ?

    That looks OK. (Sunny weather keeps me away from my PC as well )

  39. #39

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    ah
    finally its finished!
    Thanks alot mate, really helpful! -rates-
    And yeah, i think it keeps everyone away from the pc, but its not even summer yet and its like 25c :S
    Kankerflecken.

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Tamworth, UK
    Posts
    82

    Re: Registry Manipulation ?

    And also, this is the 3rd most popular topic in this section
    3rd out of 203,352
    :x
    Kankerflecken.

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