|
-
Apr 8th, 2007, 04:10 PM
#1
Thread Starter
Lively Member
[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)
-
Apr 8th, 2007, 04:18 PM
#2
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.

-
Apr 8th, 2007, 04:31 PM
#3
Thread Starter
Lively Member
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.
-
Apr 8th, 2007, 06:03 PM
#4
Fanatic Member
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
-
Apr 9th, 2007, 07:07 AM
#5
Re: Registry Manipulation ?
 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?
-
Apr 9th, 2007, 12:02 PM
#6
Thread Starter
Lively Member
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 >
-
Apr 9th, 2007, 06:20 PM
#7
Thread Starter
Lively Member
Re: Registry Manipulation ?
bump :'(
Last edited by kingzl3y; Apr 9th, 2007 at 06:25 PM.
-
Apr 10th, 2007, 05:17 AM
#8
Re: Registry Manipulation ?
 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.
-
Apr 12th, 2007, 03:44 PM
#9
Thread Starter
Lively Member
Re: Registry Manipulation ?
 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[....
-
Apr 13th, 2007, 04:00 AM
#10
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:
'Needs 2 command buttons and 3 textboxes.
Public Const MY_TESTKEY = "RegistryTest"
Private Sub cmdSave_Click()
'Add some test values.
txtSubkey.Text = "My Subkey"
txtValueName.Text = "My Value Name"
txtValue.Text = "My Value"
On Error GoTo SaveError
SaveSetting MY_TESTKEY, txtSubkey.Text, txtValueName.Text, txtValue.Text
Exit Sub
SaveError:
MsgBox ("Error in cmdSave_Click")
Exit Sub
End Sub
Private Sub cmdGet_Click()
On Error GoTo GetError
txtValue.Text = GetSetting(MY_TESTKEY, txtSubkey.Text, txtValueName.Text, "Default")
Exit Sub
GetError:
MsgBox ("Error in cmdGet_Click")
Exit Sub
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
-
Apr 13th, 2007, 05:31 PM
#11
Thread Starter
Lively Member
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
-
Apr 14th, 2007, 06:03 AM
#12
Re: Registry Manipulation ?
 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:
Option Explicit 'ALWAYS !!!!!!!
Dim ProxyEnableCheck As Integer
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.
'Check if disabled or enabled.
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 '??????????
Case 1 'Ticked.
Text1.Enabled = True
'Same as above.....
' lblProxyStatus.Caption = "Proxy Enabled" & lblProxyStatus.ForeColor = &HFF00 '??????????
Case 2 'Greyed.
'Nothing to do.
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
-
Apr 14th, 2007, 07:17 AM
#13
Thread Starter
Lively Member
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
-
Apr 15th, 2007, 02:57 AM
#14
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
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"
-
Apr 15th, 2007, 07:12 AM
#15
New Member
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.
-
Apr 16th, 2007, 03:41 PM
#16
Thread Starter
Lively Member
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*
-
Apr 16th, 2007, 03:44 PM
#17
Thread Starter
Lively Member
Re: Registry Manipulation ?
 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
-
Apr 16th, 2007, 04:49 PM
#18
Thread Starter
Lively Member
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)
-
Apr 16th, 2007, 05:11 PM
#19
New Member
Re: Registry Manipulation ?
 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
-
Apr 17th, 2007, 11:02 AM
#20
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:
Private Sub ProxySettings(Address As String, Enable As Integer)
Dim objCreate As Object
Set objCreate = CreateObject("wscript.shell")
'On Error etc... - similar to that in Form_Load.
objCreate.RegWrite ProxyEnable, Enable, "REG_DWORD"
'On Error etc... - similar to that in Form_Load.
objCreate.RegWrite ProxyServer, Address, "REG_SZ"
Exit Sub
SaveError:
'Suitable error messaging here - similar to that in Form_Load.
'MsgBox "Error!", vbCritical, "Error Found"
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.
-
Apr 18th, 2007, 04:55 PM
#21
Thread Starter
Lively Member
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:
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
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF
Text1.Enabled = False
Case 1
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &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()
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
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. 
-
Apr 18th, 2007, 05:09 PM
#22
Thread Starter
Lively Member
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:
Save a text string:
Text$="Stuff to Save"
SaveSetting "MyProgram", "MySection", "TextValue1", Text$
Get your strng back
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. 
-
Apr 19th, 2007, 12:06 PM
#23
Re: Registry Manipulation ?
 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:
Dim AllowEvents As Boolean
to the declarations section of the form, and
vb Code:
Private Sub Form_Initialize()
AllowEvents = False
End Sub
and
vb Code:
If AllowEvents = False Then Exit Sub
as the first line in "Check1_Click", to prevent false triggering, and 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 then add a sub...
vb Code:
Public Sub FirstRunCheck()
Dim strHasItRunBefore As String
'If the value doesn't exist, will return "0"
strHasItRunBefore = GetSetting(App.EXEName, "FirstRun", "RunFlag", "0")
If strHasItRunBefore = "0" Then
'So... this IS the first run, - change the flag to "1".
SaveSetting App.EXEName, "FirstRun", "RunFlag", "1"
'Save other settings code here...
SaveSetting App.EXEName, "Settings", "ProxyServer", txtProxyStatus.Text
'Similar for the CheckBox, and any other settings...
'------------
'------------
'------------
'------------
End If
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".
-
Apr 19th, 2007, 01:21 PM
#24
Thread Starter
Lively Member
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. 
-
Apr 19th, 2007, 01:41 PM
#25
Re: Registry Manipulation ?
Yep, that looks ok.
 Originally Posted by kingzl3y
Btw, you're English right?
I most certainly am.
-
Apr 19th, 2007, 04:26 PM
#26
Thread Starter
Lively Member
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:
Public Sub FirstRunCheck()
Dim strHasItRunBefore As String
'If the value doesn't exist, will return "0"
strHasItRunBefore = GetSetting(Pr0xytool, "FirstRun", "RunFlag", "0")
If strHasItRunBefore = "0" Then
'So... this IS the first run, - change the flag to "1".
SaveSetting Pr0xytool, "FirstRun", "RunFlag", "1"
'Save other settings code here...
SaveSetting Pr0xytool, "Settings", "ProxyServer", txtProxyStatus.Text
'Similar for the CheckBox, and any other settings...
'------------
'-----------
'------------
'------------
End If
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. 
-
Apr 19th, 2007, 04:56 PM
#27
Thread Starter
Lively Member
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:
Private Sub menuExit_Click()
Unload Me ' exit app
End Sub
Private Sub menuRestore_Click()
'Restore original Settings
End Sub
Think thats a better idea, then having an additional button?
Kankerflecken. 
-
Apr 20th, 2007, 05:52 PM
#28
Thread Starter
Lively Member
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:
In the Form_load
vb Code:
Public Sub FirstRuncheck()
Dim strRanbefore As String
On Error GoTo GetError
strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0")
If strRanbefore = 0 Then
On Error GoTo SaveError
SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text
End If
Exit Sub
GetError:
MsgBox ("Error checking if program has ran before")
Exit Sub
SaveError:
MsgBox ("Error Saving Firstrun status")
Exit Sub
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:
Private Sub menuRestore_Click()
txtProxyAddress = GetSetting("Pr0xytool", "Settings", "Proxyserver")
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. 
-
Apr 22nd, 2007, 02:33 PM
#29
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:
Private Sub menuRestore_Click()
txtProxyAddress.Text = "" '<------
txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver")
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 )
-
Apr 22nd, 2007, 03:31 PM
#30
Thread Starter
Lively Member
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:
If Proxyserver = ""
then
'whatever, i cannot think what to put ><"
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. 
-
Apr 23rd, 2007, 02:23 PM
#31
Re: Registry Manipulation ?
At this point you could (in Form_Load):-
vb Code:
'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)
-
Apr 23rd, 2007, 02:25 PM
#32
Thread Starter
Lively Member
Re: Registry Manipulation ?
Uhuhm, what do you mean, comment out the message box? :x
Kankerflecken. 
-
Apr 23rd, 2007, 02:36 PM
#33
Re: Registry Manipulation ?
In the error handler in Form_Load:-
vb Code:
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
Leave "Resume Next" uncommented so that the rest of the code runs.
-
Apr 23rd, 2007, 03:08 PM
#34
Thread Starter
Lively Member
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:
'*******************
'Author: Kingzl3y
'Name: Proxy tool
'Description: Enable/Disable and edit proxy address
'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
'Have fun
'Website - Coming soon.
'*******************
Option Explicit 'ALWAYS !!!!!!!
Dim AllowEvents As Boolean ' Define AllowEvens as boolean
Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
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
txtProxyAddress = 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
txtProxyAddress.Enabled = False
Case 1
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
AllowEvents = True
FirstRuncheck
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 txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
Select Case Check1.Value
Case 0 ' if proxy is disabled then
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF
txtProxyAddress.Enabled = False
Case 1 ' if proxy is enabled then
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.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 menuExit_Click()
Unload Me
End Sub
Private Sub menuRestore_Click()
txtProxyAddress.Text = "" '<------
txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
MsgBox "Original Settings restored - " & txtProxyAddress.Text
End Sub
Public Sub FirstRuncheck()
Dim strRanbefore As String
On Error GoTo GetError
strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
If strRanbefore = 0 Then
On Error GoTo SaveError
SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
End If
Exit Sub
GetError:
MsgBox ("Error checking if program has ran before")
Exit Sub
SaveError:
MsgBox ("Error Saving Firstrun status")
Exit Sub
End Sub
Private Sub Text1_Click()
MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
End Sub
Kankerflecken. 
-
Apr 23rd, 2007, 03:47 PM
#35
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
-
Apr 25th, 2007, 04:35 PM
#36
Thread Starter
Lively Member
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:
'*******************
'Author: Kingzl3y
'Name: Proxy tool
'Description: Enable/Disable and edit proxy address
'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
'Have fun
'Website - Coming soon.
'*******************
Option Explicit 'ALWAYS !!!!!!!
Dim AllowEvents As Boolean ' Define AllowEvens as boolean
Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
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
txtProxyAddress = 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
txtProxyAddress.Enabled = False
Case 1
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
AllowEvents = True
FirstRuncheck
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 txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
Select Case Check1.Value
Case 0 ' if proxy is disabled then
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF&
txtProxyAddress.Enabled = False
Case 1 ' if proxy is enabled then
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.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 menuExit_Click()
Unload Me
End Sub
Private Sub menuRestore_Click()
txtProxyAddress.Text = "" '<------
txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
Check1.Value = GetSetting("pr0xytool", "Settings", "Proxystatus", 0) ' Restore original proxy status (on/off)
MsgBox "Original Settings restored - " & txtProxyAddress.Text & vbNewLine & " Proxy Enabled - " & Check1.Value
End Sub
Public Sub FirstRuncheck()
Dim strRanbefore As String
On Error GoTo GetError
strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
If strRanbefore = 0 Then
On Error GoTo SaveError
SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
SaveSetting "Pr0xytool", "Settings", "ProxyStatus", CInt(Check1.Value) ' saves proxy status (on/off)
End If
Exit Sub
GetError:
MsgBox ("Error checking if program has ran before")
Exit Sub
SaveError:
MsgBox ("Error Saving Firstrun status")
Exit Sub
End Sub
Private Sub Text1_Click()
MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
End Sub
Kankerflecken. 
-
Apr 28th, 2007, 05:59 AM
#37
Thread Starter
Lively Member
Re: Registry Manipulation ?
AHWEHWEHWEHWH
Dude, i think i've done it
and it seems to work perfectly!
Once last look
vb Code:
'*******************
'Author: Kingzl3y
'Name: Proxy tool
'Description: Enable/Disable and edit proxy address
'Special thanks too - SchoolBusdriver @ [url]www.vb-forums.com[/url]
'Have fun
'Website - Coming soon.
'*******************
Option Explicit 'ALWAYS !!!!!!!
Dim AllowEvents As Boolean ' Define AllowEvens as boolean
Const ProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer" ' Proxy server located in registry
Const ProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" ' Proxy status located in registry
Private Sub Form_Initialize()
AllowEvents = False
End Sub
Private Sub Check1_Click()
If AllowEvents = False Then Exit Sub
Select Case Check1.Value
Case 0 ' if proxy is disabled then
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF&
txtProxyAddress.Enabled = False
Case 1 ' if proxy is enabled then
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
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
txtProxyAddress = 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
txtProxyAddress.Enabled = False
Case 1
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.Enabled = True
End Select
AllowEvents = True
FirstRuncheck
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 txtProxyAddress, Check1.Value ' save proxy settings as "Server" - "Status"(either 1/enabled or 0/disabled)
Select Case Check1.Value
Case 0 ' if proxy is disabled then
txtProxyStatus.Text = "Proxy Disabled"
txtProxyStatus.BackColor = &HFF&
txtProxyAddress.Enabled = False
Case 1 ' if proxy is enabled then
txtProxyStatus.Text = "Proxy Enabled"
txtProxyStatus.BackColor = &HFF00&
txtProxyAddress.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 menuExit_Click()
Unload Me
End Sub
Private Sub menuRestore_Click()
txtProxyAddress.Text = "" '<------
txtProxyAddress.Text = GetSetting("Pr0xytool", "Settings", "Proxyserver") ' Restore orignal proxy server.
Check1.Value = GetSetting("pr0xytool", "Settings", "Proxystatus", 0) ' Restore original proxy status (on/off)
ProxySettings txtProxyAddress, Check1.Value ' Save restored settings to main registry
MsgBox "Original Settings restored - " & txtProxyAddress.Text & vbNewLine & " Proxy Enabled - " & Check1.Value
End Sub
Public Sub FirstRuncheck()
Dim strRanbefore As String
On Error GoTo GetError
strRanbefore = GetSetting("Pr0xytool", "FirstRun", "RunFlag", "0") ' If first run, then backup proxyserver address.
If strRanbefore = 0 Then
On Error GoTo SaveError
SaveSetting "Pr0xytool", "FirstRun", "RunFlag", "1"
SaveSetting "Pr0xytool", "Settings", "ProxyServer", txtProxyAddress.Text ' saves original proxy address
SaveSetting "Pr0xytool", "Settings", "ProxyStatus", CInt(Check1.Value) ' saves proxy status (on/off)
End If
Exit Sub
GetError:
MsgBox ("Error checking if program has ran before")
Exit Sub
SaveError:
MsgBox ("Error Saving Firstrun status")
Exit Sub
End Sub
Private Sub txtProxyAddress_Click()
MsgBox "Format = Address:Port", vbInformation, "Please use correct format" ' shows correct format
End Sub
gui @

Kankerflecken. 
-
Apr 29th, 2007, 03:20 AM
#38
Re: Registry Manipulation ?
That looks OK. (Sunny weather keeps me away from my PC as well )
-
Apr 29th, 2007, 04:33 AM
#39
Thread Starter
Lively Member
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. 
-
Apr 29th, 2007, 04:38 AM
#40
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|