VBS Help

Discussion in 'Software' started by bmpbmp1975, Mar 27, 2007.

  1. bmpbmp1975

    bmpbmp1975 Private E-2

    I have exported 2 registry keys one that turns on a proxy in internet explorer and the other one that turns it off. I want to create a menu option that gives a user the choice of it on or off without haveing to see both files just a exe or vbs that they click and it will ask them if they want to use proxy or not and this will choose the right file to run.

    Does anyone know how I can do this.

    or I tried this

    I got this in vbs and this does not use my registry keys

    Const REG_ENTRY = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\"

    Set Shell = CreateObject("WScript.Shell")
    Path = REG_ENTRY

    'On Error resume next
    CurrentValue = Shell.RegRead(Path & "ProxyEnable")

    If CurrentValue="" Then
    Response = MsgBox ("Your Proxy is set to : Direct Internet " & _
    vbCrLf & _
    "Would you like to change it to VPN?", vbYesNo, "CDS VPN Script for IE")
    If Response = vbYes Then
    Shell.RegWrite Path & "AutoConfigURL", ""
    Shell.RegWrite Path & "ProxyEnable","1"
    Shell.RegWrite Path & "ProxyServer", "titan2.studio.cdsorg.net:80"
    End If

    Else
    Response = MsgBox ("Your Proxy is set to : " & _
    CurrentValue & vbCrLf & _
    "Would you like to change it to DIRECT INTERNET?", vbYesNo, "CDS VPN Script for IE")
    If Response = vbYes Then
    Shell.RegWrite Path & "AutoConfigURL", ""
    Shell.RegWrite Path & "ProxyEnable","0"
    Shell.RegWrite Path & "ProxyServer","titan2.studio.cdsorg.net:80"
    End If

    End if


    When the proxy is off the vbs turns it on my problem now is when it is on the vbs does not turn it off.

    Anyone have any ideas.
     
  2. Mada_Milty

    Mada_Milty MajorGeek

    Could your problem be that your script sets the value of "ProxyEnable" to either 1 or 0, but only checks whether it is null or not?

    Code:
    Const REG_ENTRY = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
    
    Set Shell = CreateObject("WScript.Shell")
    Path = REG_ENTRY
    
    'On Error resume next
    CurrentValue = Shell.RegRead(Path & "ProxyEnable")
    
    If CurrentValue="" [B][SIZE="4"][COLOR="Red"]or CurrentValue="0"[/COLOR][/SIZE][/B] Then
    Response = MsgBox ("Your Proxy is set to : Direct Internet " & _
    vbCrLf & _
    "Would you like to change it to VPN?", vbYesNo, "CDS VPN Script for IE")
    If Response = vbYes Then
    Shell.RegWrite Path & "AutoConfigURL", ""
    Shell.RegWrite Path & "ProxyEnable","1"
    Shell.RegWrite Path & "ProxyServer", "titan2.studio.cdsorg.net:80"
    End If
    
    [B][SIZE="4"][COLOR="Red"]Elseif CurrentValue = "1"[/COLOR][/SIZE][/B]
    Response = MsgBox ("Your Proxy is set to : " & _
    CurrentValue & vbCrLf & _
    "Would you like to change it to DIRECT INTERNET?", vbYesNo, "CDS VPN Script for IE")
    If Response = vbYes Then
    Shell.RegWrite Path & "AutoConfigURL", ""
    Shell.RegWrite Path & "ProxyEnable","0"
    Shell.RegWrite Path & "ProxyServer","titan2.studio.cdsorg.net:80"
    End If
    
    End if
    Does this code work? (Changes are in red)
     
  3. bmpbmp1975

    bmpbmp1975 Private E-2

    Thanks Mada but it does not work, it adds the proxy when not there but it does not remove it
     
  4. Mada_Milty

    Mada_Milty MajorGeek

    As a next step, would it be prudent to try removing the hostname for the proxy when the user chooses to turn it off?

    Currently, when either condition is met, you have a registry write that sets the value of "ProxyServer" to "titan2.studio.cdsorg.net:80". Would it be better to set it to null when we want the proxy off?
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds