Sometimes, we only need to update software on certain systems, as not every system is created equal. For this reason, you can use the if exist line in a batch file.
Here's an example of using the if exist and goto
Let's say that you want to run an install on all machines but you do not want to run the update every time a system logs onto the network, you can add this code to your logon script.
REM ** The REM statement is for comments**
REM ** The first line checks to see if the update.txt file exists, ensuring that the update hasn't already been run.
if exist "c:\update\update.txt" goto End
REM ** If the update.txt file is not present, the following code would be run.
REM ** Map network drive
net use z: \\server\share
REM ** Change to the newly mapped z: drive.
z:
REM ** Change the following to your command that you would run.
installupdate.exe /quiet
REM ** Because we just installed the update, we want to copy the update.txt file to the update folder to
REM ** ensure that the update does not run again on this system.
copy \\server\share\update.txt c:\update\
REM ** No more need for that mapped drive, so let's disconnect it.
net use z: /d
REM ** If the file existed, the update.txt file would have been present and the script would exit.
End:
exit
I hope this example helps you understand the usage and importance of this batch file. We use something similar to this on a regular basis.
No comments:
Post a Comment