1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

Batch file for laptops to modify proxy settings

Discussion in 'Windows Home Server' started by msvge@community.nospam, May 17, 2009.

  1. Have created two reg files, one to turn on proxy and one to turn proxy off
    when remote. Need a batch file that detects whether
    the laptop is on or off of the network. When outside the LAN I need the
    proxy settings to be off, and on when connected to the LAN.

    My code that doesn't work:

    C:\Documents and Settings\All Users\Start Menu\Programs\Startup

    ProxyServer.bat

    If %LOGONSERVER%==\\VGEPDC goto proxyon
    :proxyon
    echo %LOGONSERVER%
    (regedit.exe /s "c:\Temp\proxyon.reg")
    goto endif
    :else
    (regedit.exe /s "c:\Temp\proxyoff.reg")
    :endif

    batch file runs on startup but seems as though %LOGONSERVER% never changes
    to instantiate else statement
     
  2. <msvge@community.nospam> wrote in message
    news:u2sXGbw1JHA.4756@TK2MSFTNGP05.phx.gbl...
    > Have created two reg files, one to turn on proxy and one to turn proxy off
    > when remote. Need a batch file that detects whether
    > the laptop is on or off of the network. When outside the LAN I need the
    > proxy settings to be off, and on when connected to the LAN.
    >
    > My code that doesn't work:
    >
    > C:\Documents and Settings\All Users\Start Menu\Programs\Startup
    >
    > ProxyServer.bat
    >
    > If %LOGONSERVER%==\\VGEPDC goto proxyon
    > :proxyon
    > echo %LOGONSERVER%
    > (regedit.exe /s "c:\Temp\proxyon.reg")
    > goto endif
    > :else
    > (regedit.exe /s "c:\Temp\proxyoff.reg")
    > :endif
    >
    > batch file runs on startup but seems as though %LOGONSERVER% never changes
    > to instantiate else statement


    The correct syntax for the if-then-else statement is:
    If /i %LOGONSERVER%==\\VGEPDC (
    do something
    do another thing
    ) else (
    do a third thing
    do a fourth thing
    )

    About the on/off-the-network question: Your code checks what authority
    validated the current log-on session. This will obviously tell you nothing
    meaningful when the user disconnects the machine from the network. Perhaps
    something like this will meet your requirements:

    ping 192.168.1.1 -n 1 > find /i "bytes=" > nul
    if %ErrorLevel%==0 (
    do something
    do another thing
    ) else (
    do a third thing
    do a fourth thing
    )
    I'm assuming that your server's IP address is 192.168.1.1.
     
  3. <msvge@community.nospam> wrote in message news:u2sXGbw1JHA.4756@TK2MSFTNGP05.phx.gbl...
    > Have created two reg files, one to turn on proxy and one to turn proxy off
    > when remote. Need a batch file that detects whether
    > the laptop is on or off of the network. When outside the LAN I need the
    > proxy settings to be off, and on when connected to the LAN.
    >
    > My code that doesn't work:
    >
    > C:\Documents and Settings\All Users\Start Menu\Programs\Startup
    >
    > ProxyServer.bat
    >
    > If %LOGONSERVER%==\\VGEPDC goto proxyon
    > :proxyon
    > echo %LOGONSERVER%
    > (regedit.exe /s "c:\Temp\proxyon.reg")
    > goto endif
    > :else
    > (regedit.exe /s "c:\Temp\proxyoff.reg")
    > :endif
    >
    > batch file runs on startup but seems as though %LOGONSERVER% never changes
    > to instantiate else statement
    >
    >



    I'm not the greatest at batch files, but a quick glance says you should remove the ":" in front of the else statement, otherwise it is looking at it as a tag and not a command. I would also probably make it flow a little better so one, it is easier read, and two, the logic flow makes a little more sense.

    Try it this way:


    If %LOGONSERVER%==\\VGEPDC (goto proxyon)
    else
    (regedit.exe /s "c:\Temp\proxyoff.reg")
    goto endif
    :proxyon
    echo %LOGONSERVER%
    (regedit.exe /s "c:\Temp\proxyon.reg")
    :endif


    --
    Ace

    This posting is provided "AS-IS" with no warranties or guarantees and
    confers no rights.

    Ace Fekay, MCSE 2003 & 2000, MCSA 2003 & 2000, MCSA Messaging, MCT
    Microsoft Certified Trainer
    aceman@mvps.RemoveThisPart.org

    For urgent issues, you may want to contact Microsoft PSS directly. Please
    check http://support.microsoft.com for regional support phone numbers.

    "Efficiency is doing things right; effectiveness is doing the right things." - Peter F. Drucker
    http://twitter.com/acefekay
     
  4. "Pegasus [MVP]" <news@microsoft.com> wrote in message news:%23bbMFTx1JHA.1716@TK2MSFTNGP03.phx.gbl...
    > The correct syntax for the if-then-else statement is:
    > If /i %LOGONSERVER%==\\VGEPDC (
    > do something
    > do another thing
    > ) else (
    > do a third thing
    > do a fourth thing
    > )
    >
    > About the on/off-the-network question: Your code checks what authority
    > validated the current log-on session. This will obviously tell you nothing
    > meaningful when the user disconnects the machine from the network. Perhaps
    > something like this will meet your requirements:
    >
    > ping 192.168.1.1 -n 1 > find /i "bytes=" > nul
    > if %ErrorLevel%==0 (
    > do something
    > do another thing
    > ) else (
    > do a third thing
    > do a fourth thing
    > )
    > I'm assuming that your server's IP address is 192.168.1.1.
    >
    >


    Sorry Pegasus. I didn't refresh my newsreader to see you've already responded to it before I did.

    Ace
     
  5. "Ace Fekay [Microsoft Certified Trainer]" <aceman@mvps.RemoveThisPart.org>
    wrote in message news:eKcLHQ01JHA.1864@TK2MSFTNGP02.phx.gbl...

    Sorry Pegasus. I didn't refresh my newsreader to see you've already
    responded to it before I did.

    Ace

    =========

    No problem!
     

Share This Page