We help IT Professionals succeed at work.

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

ApexTx
ApexTx asked
on
432 Views
Last Modified: 2010-05-03
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.
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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

Author

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


Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.