Link to home
Start Free TrialLog in
Avatar of cpark00
cpark00Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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  
Avatar of conradjones
conradjones

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”."
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
Avatar of merowinger
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

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
Avatar of cpark00

ASKER

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

Avatar of cpark00

ASKER

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

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

Avatar of cpark00

ASKER

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
..............
Avatar of cpark00

ASKER

I've checked already if the .CAB file and the computer's name are spelt right
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.
could you please post the output of the messages which are displayed?
Avatar of cpark00

ASKER

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

Avatar of cpark00

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of merowinger
merowinger
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cpark00

ASKER

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.