Results 1 to 5 of 5

Thread: Batch file for laptops to modify proxy settings

  1. #1
    Guest

    Batch file for laptops to modify proxy settings

    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. #2
    Pegasus [MVP] Guest

    Re: Batch file for laptops to modify proxy settings


    <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    Ace Fekay [Microsoft Certified Trainer] Guest

    Re: Batch file for laptops to modify proxy settings

    <[email protected]> wrote in message news:[email protected]...
    > 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
    [email protected]

    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. #4
    Ace Fekay [Microsoft Certified Trainer] Guest

    Re: Batch file for laptops to modify proxy settings

    "Pegasus [MVP]" <[email protected]> wrote in message news:%[email protected]...
    > 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. #5
    Pegasus [MVP] Guest

    Re: Batch file for laptops to modify proxy settings


    "Ace Fekay [Microsoft Certified Trainer]" <[email protected]>
    wrote in message news:[email protected]...

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

    Ace

    =========

    No problem!



Similar Threads

  1. Can I modify fan settings of Sparkle GTX 570 Calibre
    By golden moon in forum Monitor & Video Cards
    Replies: 6
    Last Post: 16-08-2011, 10:27 AM
  2. How to Customize IE Proxy settings?
    By Gavinovo in forum Windows Software
    Replies: 5
    Last Post: 18-10-2010, 09:48 PM
  3. Not able to modify hardware acceleration settings
    By Alysa in forum Monitor & Video Cards
    Replies: 5
    Last Post: 03-08-2010, 02:00 AM
  4. Proxy settings in Utorrent
    By TalinF in forum Technology & Internet
    Replies: 4
    Last Post: 23-06-2010, 06:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,749,958,379.30907 seconds with 16 queries