Link to home
Start Free TrialLog in
Avatar of ApexTx
ApexTx

asked on

Need to copy a file to a bunch of pc's at one time.

I have a situation where I need to update a file on a bunch of computers. Obviously I don't want to have to manually do the copying and I don't want to have to install any software or tools. I would like to write an app or even a script if that would work better. I need this for work like yesterday. Points will go to the first doable code that works for me.
ASKER CERTIFIED SOLUTION
Avatar of ScrptMasta
ScrptMasta

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

If u are using Novell Network then u can copy ur file in the working directory and add the copy command in the host file. When ever the computer boots it shall run the host file and copy the file onto the computer. This might be possible in other networks also, but i am not sure about that.

I hope this is useful.

Sac
It is necessary for us to know are you have write access to shared folders on all computers ?
How you copy this file until now ? From one central place to all computers, or you sit on every computer and copy file from some central place ?

If we can't know answers of these wuestions we can give to you only suggestions. Please, describe your problem as more as possible.

One possible solution (if you have write access to shared folder on remote computers ?!?!? and if file on remote computers are not locked from some app on it ?!?!?) is to write an app, wich will copy this file to every computer like this:


On Error Resume Next

Dim lngL As Long
Dim lngCompsCount As Long
Dim mstrCompIPs() As String

 ' Set number of computers on your network, that must be provided with new file
lngCompsCount=50 ' Change 50 with number of computers
 ' Fill computer IP's in string array
ReDim mstrCompIPs(lngCompsCount) As String
mstrCompIPs(1)="192.168.0.2"
mstrCompIPs(2)="192.168.0.10"
mstrCompIPs(3)="192.168.0.15"
mstrCompIPs(4)="192.168.0.23"
mstrCompIPs(5)="192.168.0.26"
 ' Fill all members of mstrCompIPs with IP addresses of computers need updated file
 ' If IP addresses are ordered, you can you some loop to fill mstrCompIPs

 ' Use FileCopy to copy local file to remote shared folder
For lngL=1 To lngCompsCount
    ' Clear error
   Err.Clear
    ' Perform FileCopy of local file to remote computer shared folder
   FileCopy "C:\MyDir\MyNewFile.doc" , "\\" & mstrCompIPs(lngL) & "\SharedFolderOnRemoteComputer\MyNewFile.doc"
    ' If some error occur print it to immediate window
   If Err.Number<>0 Then
      Debug.Print Now & " -> " & lngL & " (" & mstrCompIPs(lngL) & ") -> " & Err.Description
       ' Clear Error
     Err.Clear
   End If
Next 'lngL


In above example, FileCopy looks like this (example is for first IP address):

FileCopy "C:\MyDir\MyNewFile.doc" , "\\192.168.0.2\NewDocs\MyNewFile.doc"

If you have write access to remote computers, there is no reason FileCopy to fail.
Information on failure is provided in immediate window if for some reason FileCopy fails.


Excuse me for my bad English.
Hope this helps.
Best regards,
Georgi Ganchev
Avatar of ApexTx

ASKER

Thanks for all who have replied however I think that ScrptMasta's has provided the best solution to what I need and his code works without needed modification.

ScrptMasta I will give you another 500 points if you show me how to do the check piece afterwards.

Thanks.
Ok basically what we are going to do is similar to the above script. We just need to check a property on the file that you are updating. My guess is that the file size will change as a result of this upgrade so this is what we can check. We should setup a log file and have the results of each query get sent to the log file. This script assumes that the size of the new file should be 96450.

logfile = "C:\logfile.log"
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Sub tolog(ltext, state)

      If state=1 Then
            wscript.echo ltext
      End If

      Set fso = CreateObject("Scripting.FileSystemObject")
      Set objFile = fso.OpenTextFile(logfile, 8, True)
      objFile.WriteLine ltext
      objFile.Close

End Sub

'**************************************************************************

Const OverwriteExisting = True

dim ip, myip

myip = Array(63,64,65,66,67,68,69,70,72,73,74,79,80,81)

For Each ip in myip

     Set WshShell = CreateObject("WScript.Shell")
     Set FSO = CreateObject("Scripting.FileSystemObject")

     WshShell.Run ("cmd /c net use y: \\10.1.1." & ip & "\d$ /user:admin password")
          wscript.sleep 2000
     set f = FSO.GetFile ("y:\myfolder\myfile.txt")
          If f.Size = 96450 Then
               tolog "The file on computer 10.1.1." & ip & " has been properly updated.", 0
          Else
               tolog ""The file on computer 10.1.1." & ip & " has NOT been properly updated.", 0
          End If
Next

'******************************************************************************

After this runs you should have a file called logfile.log on the root of the C:\ which contains all of the pcs and whether or not they have received the update.



Remove the second quotes from the line.

tolog "The file on computer 10.1.1." & ip & " has NOT been properly updated.", 0

I had a typ there it should be:

tolog "The file on computer 10.1.1." & ip & " has NOT been properly updated.", 0

Sorry