chaffee007
asked on
Copy folder/file to mutiple computers
I would like to copy a file to all computers on my network. (bginfo.exe). Is there an easy .bat that I can specify a relative computer name instead of listing each one in xcopy? Or, do I need to use .vbs?
You could use a login script...something like: "xcopy \\server\share\bginfo.exe c:\"
You can also do this with .bat file.
* Following script needs Computers.txt file on C: drive root from where it pick the destination host name where you want to copy the file.
* Copy and paste following script into notepad.exe and save it with any name having .bat extension.
:: Batch Script Start
@Echo Off
FOR /F "delims=#" %%c IN (C:\Computers.txt) Do (
Echo Copying file to system: %%c
XCopy C:\Folder\bginfo.exe \\%%c\D$\Folder\
REM OR
REM XCopy /Y \\Server\Share\bginfo.exe \\%%c\C$\Folder\
)
Echo Files copied.
Pause
Exit
:: Batch Script End
* Following script needs Computers.txt file on C: drive root from where it pick the destination host name where you want to copy the file.
* Copy and paste following script into notepad.exe and save it with any name having .bat extension.
:: Batch Script Start
@Echo Off
FOR /F "delims=#" %%c IN (C:\Computers.txt) Do (
Echo Copying file to system: %%c
XCopy C:\Folder\bginfo.exe \\%%c\D$\Folder\
REM OR
REM XCopy /Y \\Server\Share\bginfo.exe \\%%c\C$\Folder\
)
Echo Files copied.
Pause
Exit
:: Batch Script End
Assuming you have an Active Directory infrastructure then you could use a startup script (which has system permissions on the local PC when it executes).
IF NOT EXIST "%ProgramFiles%\BGINFO" (
MD "%ProgramFiles%\BGINFO"
COPY "%~0\..\BGINFO.EXE" "%ProgramFiles%\BGINFO"
)
This script will check for the existence of 'C:\Program Files\BGINFO' and assuming it is not there, create a folder 'C:\Program Files\BGINFO' then copy BGINFO.EXE from the same folder as the script into 'C:\Program Files\BGINFO'.
If you really do want to copy files to a 'list' of computers then this script should do it
@echo off
for /F "tokens=*" %%1 in (list.txt) do (
echo Checking %%1
if not exist "\\%%1\c$\Program Files\BGINFO" (
echo Copying files to %%1
MD "\\%%1\c$\Program Files\BGINFO"
copy "%~0\..\bginfo.exe" "\\%%1\c$\Program Files\BGINFO"
)
)
The script will read a list file (list.txt) and assuming each line in the file is a computername, it will check to see if BGINFO exists in 'C:\Program Files'. If not, then it attempts to copy the file there. The file is copied from the same folder as the script as in the earlier example
An example lists.txt would look like this
COMPUTERNAME01
COMPUTERNAME02
COMPUTERNAME03
IF NOT EXIST "%ProgramFiles%\BGINFO" (
MD "%ProgramFiles%\BGINFO"
COPY "%~0\..\BGINFO.EXE" "%ProgramFiles%\BGINFO"
)
This script will check for the existence of 'C:\Program Files\BGINFO' and assuming it is not there, create a folder 'C:\Program Files\BGINFO' then copy BGINFO.EXE from the same folder as the script into 'C:\Program Files\BGINFO'.
If you really do want to copy files to a 'list' of computers then this script should do it
@echo off
for /F "tokens=*" %%1 in (list.txt) do (
echo Checking %%1
if not exist "\\%%1\c$\Program Files\BGINFO" (
echo Copying files to %%1
MD "\\%%1\c$\Program Files\BGINFO"
copy "%~0\..\bginfo.exe" "\\%%1\c$\Program Files\BGINFO"
)
)
The script will read a list file (list.txt) and assuming each line in the file is a computername, it will check to see if BGINFO exists in 'C:\Program Files'. If not, then it attempts to copy the file there. The file is copied from the same folder as the script as in the earlier example
An example lists.txt would look like this
COMPUTERNAME01
COMPUTERNAME02
COMPUTERNAME03
Oops! Took so long composing my comment someone beat me to it!
ASKER
ajbritton,
I like that method, but do I have to remove the startup script form GP when I am done?
I like that method, but do I have to remove the startup script form GP when I am done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.