neon Posted December 14, 2009 Posted December 14, 2009 I am new to Visual Basic and am looking for a little help. I have 2 .vbs files (which I got off edugeek) that I can double click one to turn on proxy settings and one to turn them off, I have managed to get my hands on visual basic studio 2005 and wanted to make a simple app but I am finding it difficult, here is the script Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable","1","REG_DWORD" WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer","PROXY:PORT","REG_SZ" Wscript.Echo " Proxy Settings Added " I have designed the app and wanted to add funtionality to one of the buttons... thought I could double click the button and paste the code in? Obv not... Is it because wshshell cannot run inside visual basic studio? Any help welcomed...
localzuk Posted December 14, 2009 Posted December 14, 2009 VBS is different to Visual Basic .net - one is a scripting language, the other is a programming language. To make an application which would switch reg settings on the press of a button, you'd need to make use of the Microsoft.Win32 library, and the 'Registry' and 'RegistryKey' objects. I'd suggest grabbing a VB.Net book and picking up the basics of the language before trying that though. Personally, I'd also say to use C# instead of VB.net - the syntax makes more sense I find.
neon Posted December 14, 2009 Author Posted December 14, 2009 Thank you, thought that they were the same but visual basic let you create a a GUI... Back to the books...
jmcdermott Posted December 14, 2009 Posted December 14, 2009 Not sure if it helps but here is the VB6 code to perform this task. dim key as string dim create dim regsetting key = "HKEY_CURRENT_USER\software\microsoft\windows\currentversion\internet settings\proxyenable" Set create = CreateObject("wscript.shell") regsetting = 1 create.regwrite key, regsetting, "REG_DWORD" 'create.regwrite ("hkcu\software\microsoft\windows\currentversion\internet settings\proxyenable", "1", "reg_dword") msgbox = "Proxy Now: Enabled"
neon Posted December 14, 2009 Author Posted December 14, 2009 I am working with visual basic 2005 express edition I got it for free and I am have very little knowledge, I have copied it in and seems to work ok, do you have one for disable proxy?
jmcdermott Posted December 14, 2009 Posted December 14, 2009 yes just change the regsetting var to 1 instead of 0.
localzuk Posted December 14, 2009 Posted December 14, 2009 Another issue there, you are using Visual Studio 2005 Express - Visual Basic edition. This is a cut down version of Visual Studio, which only allows the use of Visual Basic.net. The code that jmcdermott posted is VB6 - an older, and now defunct, language. Information on VB.net registry interaction is available here: Accessing the Registry with Visual Basic .NET
jmcdermott Posted December 14, 2009 Posted December 14, 2009 Maybe older and defunct, but it is what was around when I started IT and still serves a use. I find coding in .NET takes a lot longer to perform the simple tasks.
neon Posted December 14, 2009 Author Posted December 14, 2009 The code went in with no errors however doesnt work, maybe I should stop being a cheap skate and buy the latest version rather than messing about with this?
jmcdermott Posted December 14, 2009 Posted December 14, 2009 Which Browser are you using? Also it may require the browser to exit and open again before it takes effect.
neon Posted December 14, 2009 Author Posted December 14, 2009 (edited) What browser am I using? should it make a difference? IE8... but I can run the application and nothing happens... ublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim key As String Dim create Dim regsetting key = "HKEY_CURRENT_USER\software\microsoft\windows\currentversion\internet settings\proxyenable" create = CreateObject("wscript.shell") regsetting = 1 create.regwrite(key, regsetting, "REG_DWORD") 'create.regwrite ("hkcu\software\microsoft\windows\currentversion\internet settings\proxyenable", "1", "reg_dword") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim key As String Dim create Dim regsetting key = "HKEY_CURRENT_USER\software\microsoft\windows\currentversion\internet settings\proxyenable" create = CreateObject("wscript.shell") regsetting = 0 create.regwrite(key, regsetting, "REG_DWORD") 'create.regwrite ("hkcu\software\microsoft\windows\currentversion\internet settings\proxyenable", "0", "reg_dword") End Sub End Class This is code I have in place I only want 2 buttons one to turn on one to turn off... Edited December 14, 2009 by neon
jmcdermott Posted December 14, 2009 Posted December 14, 2009 Firefox and chrome do not user the reg setting. have you checked the reg key using regedit after running the program?
tommccann Posted December 14, 2009 Posted December 14, 2009 why use VB? there's an autoit script on this forum somewhere, very easy to change to
localzuk Posted December 14, 2009 Posted December 14, 2009 I think you're getting a bit mixed up here. VB6 code simply will not work in Visual Studio.net without special addons etc... It isn't supported any more, so unless you have the VB6 program installed, it will be no use. The code you need will be possible if you use the link I provided.
neon Posted December 14, 2009 Author Posted December 14, 2009 Thank you, I am in the process of reading through and trying out your link...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now