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
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.
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
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
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!