Vbscript change proxy setting at logon

Posted on 2005-04-07
Last Modified: 2011-04-13
I have a Vbscript that runs different a command depending on your IP Address I need this because I move between a number of different networks, some have a proxy and some don not.

It does things like add printers, maps drives etc. but one thing I can not get to work is enable or disable the proxy.

It works fine if you run the script manually but not at logon. I have striped the code down to just the proxy bit for troubleshooting.

My proxy.vbs file is in c:\proxy.vbs and configured via local computer Group Policy to run at logon. I have local and domain admin rights.

User Configuration\Windows Settings\Scripts (Logon/Logoff)\Logon

'Here is the Proxy code
Set ShellObj = WScript.CreateObject("WScript.Shell")
'Set Proxy
ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "", "REG_SZ"
ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
ShellObj.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", "192.168.*;<local>", "REG_SZ"
Question by:bwilks99

    Expert Comment

    Why don't you use the following executable?

    LVL 4

    Author Comment

    The setproxy.exe sets it to the uni and reboots the computer!

    I need to do it in a vbscript so it can run with the rest of the code. There carn't be too much wrong as it runs perfectly running it manually just not at logon.

    Expert Comment


    Might it be that during the logon process, the reference to HKEY_CURRENT_USER is still invalid because, strictly speaking, the user logon procedure has not completed and there is no "current user" logged on?

    It sounds strange however. Let me check this out.


    Accepted Solution

    It looks like we've hit the right spot -- there is no HKEY_CURRENT_USER during the logon process.

    LVL 4

    Author Comment

    We are in the right area have a read of this;

    It says that the local policy login script is run after the user is validated, maybe the profile and HKCU keys are not finished loading when the script runs?

    I have added some code to the top of the logon script to wait a while be for running (I am currently testing it)

    '"Wait until the user is logged on before we start
    Dim WSHNetwork, strUserName

    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    ' Wait until the user is really logged in...
    strUserName = ""
    While strUserName = ""
    WScript.Sleep 10000 ' 100 = 1/10 th of a second
    strUserName = WSHNetwork.UserName
    strUserDomain = WSHNetwork.UserDomain


    Expert Comment

    In case that doesn't work, I suggest that you spawn a different script:

    Set SH = CreateObject("WScript.Shell")
    Ret = SH.Run("delayedscript.vbs", , False)

    and in delayedscript.vbs, I would impose a short delay:

     WScript.sleep 10000

    LVL 4

    Author Comment

    Thanks cloabell the delay I put in worked! So I guess the HKCU was not filly loaded.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    haveThree challenge 22 91
    Fix45 challenge 15 67
    hasOne  challenge 59 66
    java continue statement 10 53
    This is an explanation of a simple data model to help parse a JSON feed
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now