Batch file to copy a .CAB File from server and save it into client computers

Hello everybody,

I would like to find out the way how I can copy a .CAB File from my share administrator resources in one on our servers and save it into my client computers (we talk about 450 computers) in C:\Program Files.

I was thinking to create a batch file to copy the file from the server and type the computer’s name on a list + the path ‘’C:\Program Files”. I am not familiar with the code and I don’t know if using VBScript will be better although I made some attempts but without success. Could anyone help me with this?

Much appreciate  
cpark00Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

conradjonesCommented:
copy \\SERVER\SHARE\FILE.CAB "C:\Program Files\File.Cab" /Y

sorry i don't understand what you mean by:

"I was thinking to create a batch file to copy the file from the server and type the computer’s name on a list + the path ‘’C:\Program Files”."
0
montague457Commented:
You could try typing in the following within the batch file:

@ECHO OFF
xcopy \\SERVER\FOLDER\*.cab c:\progra~1\*.cab /y

EXIT

I use this to copy files off of shares all the time. Works without problems. Hope I helped.

Best Regards,
DM
0
merowingerCommented:
this will copy the file from the server share to all clients which are defined in the computers.txtx file. Also there will be listed a result of the copy process in the Copy.log file
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objLog = objFSO.CreateTextFile("D:\Copy.log") 
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt") 
strFolder = "\c$\Program Files\Application" 
strFile = "\\server\share\file.cab" 
 
Do While Not objPCs.AtEndOfStream 
        strCurrentPC = objPCs.ReadLine 
         
        On Error Resume Next 
        objFSO.CopyFile strFile, Chr(34) & "\\" &strCurrentPC &strFolder &Chr(34)
        On Error GoTo 0 
        If Err.Number <> 0 Then 
                objLog.WriteLine strCurrentPC &" - Error copying file" 
        Else 
                objLog.WriteLine strCurrentPC &" - Success copying file" 
        End If 
Loop

Open in new window

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Lionel MMSmall Business IT ConsultantCommented:
This is fairly easy to accomplish. The best way is to use the logon.bat file. I assume all your PCs logon to the server. If they do then the logon.bat file can be used to test if the file you want is there and if not to copy it there. Add this line to your logon.bat file
If Not Exist C:\"Program Files"\FileName.CAB Copy \\%ServerName%\FIleLocation\FileName.CAB C:\Program Files"\FileName.CAB /y
0
cpark00Author Commented:
I tried the code copy /y "\\SERVER\SHAREFILE\FILE.CAB"c:\Program Files\FOLDER". Obviously, it was wrong.
Conradjones – your code works perfectly well but I have to run the batch file in every single computer. I am interested to run a batch file only from one computer so the batch file should have the computers’ name, for instance
copy \\SERVER\SHARE\FILE.CAB COMPUTERNAME1 "C:\Program Files\File.Cab" /Y
copy \\SERVER\SHARE\FILE.CAB COMPUTERNAME2 "C:\Program Files\File.Cab" /Y
copy \\SERVER\SHARE\FILE.CAB COMPUTERNAME3 "C:\Program Files\File.Cab" /Y
????
Could it be like that?

Lionelmm – Good idea about the login.bat but I should log on to all computer then. If I put it onto user’s logon.bat they don’t have rights to go to my share Administrator folder. This is how I understand your comment.

merowinger: I will try your code and let you know.
0
merowingerCommented:
new version without error (hopefully) ;)
Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objLog = objFSO.CreateTextFile("D:\Copy.log")  
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")  
strFolder = "\c$\Program Files\Application"  
strPath = "\\server\share\"
strFile = "file.cab"  
 
Do While Not objPCs.AtEndOfStream  
        strCurrentPC = objPCs.ReadLine  
          
        On Error Resume Next
        objFSO.CopyFile strPath  &strFile, Chr(34) & "\\" &strCurrentPC &strFolder &"\" &strFile &Chr(34),True
        If Err.Number <> 0 Then  
                objLog.WriteLine strCurrentPC &" - Error copying file: " &Err.Description  
        Else  
                objLog.WriteLine strCurrentPC &" - Success copying file"  
        End If  
Loop

Open in new window

0
cpark00Author Commented:
I maybe do something wrong as on the Copy.log appears this error for all my computer's

COMPUTERNAME1 - Error copying file: Bad file name or number
COMPUTERNAME2 - Error copying file: Bad file name or number

....
0
merowingerCommented:
please post the result of the following
Set objFSO = CreateObject("Scripting.FileSystemObject")   
Set objLog = objFSO.CreateTextFile("D:\Copy.log")   
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")   
strFolder = "\c$\Program Files\Application"   
strPath = "\\server\share\" 
strFile = "file.cab"   
  
Do While Not objPCs.AtEndOfStream   
        strCurrentPC = objPCs.ReadLine   
           
        'On Error Resume Next
	wscript.echo strPath  &strFile, Chr(34) & "\\" &strCurrentPC &strFolder &"\" &strFile &Chr(34)         
	objFSO.CopyFile strPath  &strFile, Chr(34) & "\\" &strCurrentPC &strFolder &"\" &strFile &Chr(34),True 
        If Err.Number <> 0 Then   
                objLog.WriteLine strCurrentPC &" - Error copying file: " &Err.Description   
        Else   
                objLog.WriteLine strCurrentPC &" - Success copying file"   
        End If   
Loop

Open in new window

0
cpark00Author Commented:
The only thing that I change on your code is Application in line 4: I write the name of other two folders. Where I want exactly the file.
line 5: I write my server name and the location shared
line 6: my file name.cab

On a text file I have the list of my computers
Computers.txt

COMPUTERNAME1
COMPUTERNAME2
COMPUTERNAME3
COMPUTERNAME4
......

I run the code and the Copy.log shows me

COMPUTERNAME1 - Error copying file: Bad file name or number
COMPUTERNAME2 - Error copying file: Bad file name or number
..............
0
cpark00Author Commented:
I've checked already if the .CAB file and the computer's name are spelt right
0
Lionel MMSmall Business IT ConsultantCommented:
If you users logon and logoff everyday it will update automatically--if they do not logon and off daily you could send a Net Send * (which would send a popup to all systems in the domain) to logoff. As far as the admin share goes you can move the file to a location that will allow them to copy the file. Actually this is how I distribute files and once done I remove those files from this common location.
0
merowingerCommented:
could you please post the output of the messages which are displayed?
0
cpark00Author Commented:
merowinger - The output of the messages are the ones that I wrote already. The only thing that it changes is the computer name. I won't copy 400 lines with the same format. It starts and ends like this:
COMPUTERNAME1 - Error copying file: Bad file name or number
COMPUTERNAME2 - Error copying file: Bad file name or number
...............
COMPUTERNAME400 - Error copying file: Bad file name or number

There is not more information from the Copy.log. I hope this helps.

lionelmm - It is a good solution but my users have restricted C:\Program Files

Thanks for the comments
0
merowingerCommented:
ok i think i got it
Set objFSO = CreateObject("Scripting.FileSystemObject")    
Set objLog = objFSO.CreateTextFile("D:\Copy.log")    
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")    
strFolder = "\c$\Program Files\Application"    
strPath = "\\server\share\"  
strFile = "file.cab"    
   
Do While Not objPCs.AtEndOfStream    
        strCurrentPC = objPCs.ReadLine    
            
        'On Error Resume Next          
        objFSO.CopyFile strPath  &strFile, "\\" &strCurrentPC &strFolder &"\" &strFile,True  
        If Err.Number <> 0 Then    
                objLog.WriteLine strCurrentPC &" - Error copying file: " &Err.Description    
        Else    
                objLog.WriteLine strCurrentPC &" - Success copying file"    
        End If    
Loop

Open in new window

0
cpark00Author Commented:
Hi merowinger,

It doesn't work. It comes up an error message window saying:

Line: 12
Char: 9
Error: Path not found
Code: 800A004C

It is the objFSO on Line 12
0
merowingerCommented:
insert this above line 12 and check if the pathes are correct, also a screenshot would be helpful

wscript.echo strPath  &strFile &vbnewline &"\\" &strCurrentPC &strFolder &"\" &strFile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cpark00Author Commented:
merowinger - thank you for your help! It works once I added the extra code that you wrote on your last comment.
Thanks again.

Thank you for all the comments.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.