VBScript to copy shortcut

I want to write  ascript to copy a shortcut i created to the everyone's computer for the list of compyter names i specifing in a file.  The shortcut would need to be copied to \\computername\C$\Documents and Settings\All Users\Desktop\.  How can I read the names for the computer to accomplish this from a text file.
georgedschneiderAsked:
Who is Participating?
 
sirbountyConnect With a Mentor Commented:
Probably a trailing <cr>
Try this:
'vbscript method...
 
PCList = "C:\Computers.txt"
strSC = "C:\shortcut.lnk"
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrComputers = Split(objFSO.OpenTextFile(PCList).ReadAll, vbNewLine)
 
For Each PC in arrComputers
  If PC <> "" Then objFSO.CopyFile strPC, "\\" & PC & "\Documents and Settings\All Users\Desktop"
Next

Open in new window

0
 
sirbountyCommented:
Batch method...

for /f %%a in (c:\computers.txt) do copy c:\shortcut.lnk \\%%a\c$\docume~1\alluse~1\desktop
'vbscript method...
 
PCList = "C:\Computers.txt"
strSC = "C:\shortcut.lnk"
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrComputers = Split(objFSO.OpenTextFile(PCList).ReadAll, vbNewLine)
 
For Each PC in arrComputers
  objFSO.CopyFile strPC, "\\" & PC & "\Documents and Settings\All Users\Desktop"
Next

Open in new window

0
 
georgedschneiderAuthor Commented:
Can you expalin a couple of items in the script for me?

In the line For Each PC in arrComputers where is the value for PC coming from or what is PC?  What does the split function do?  I noticed if I remove vbnewline the script fails, what does vbnewline is this a function to force a jump to the new line?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sirbountyCommented:
arrComputers is an array which is sourced by the Computers.txt file
Assuming that computers.txt is laid out as

computer1
computer2
etc...

The "PC" in the for each PC line represents one entry in that array ( the array is built by 'splitting' the file based on each carriage return after each computer name)...
0
 
georgedschneiderAuthor Commented:
What do you mean by splitting?
0
 
sirbountyCommented:
Split is a function that takes a string and separates it by a given delimeter.
So if you have a string vaule of:
1,2,3,4,5
and you split it by the comma, you'll have a 5-element array of each numeric value.
Same works for text:

string="abc,def,ghi"  'initial string
arrData=Split(string,",") 'split function to create the array
arrData(0) is now "abc" (it's a 0-based array)
arrData(1) is now "def", etc

Does that help?
0
 
georgedschneiderAuthor Commented:
Here's the problem I'm having is the script error outs at line 11.  I added on error resume next and it runs fine and everything is copied to all the PC's in the list.  In trying to determine what the cause is I added wscpt.echo strPC, "\\" & PC & "\Documents and Settings\All Users\Desktop" which produces the file loction being copied and the destination.  after the last computer in the list it produces an additioanl item \\\Documents and Settings\All Users\Desktop.  Why would this be.  There seems to be something wanting to add a balnk item to the end of the list of computers.
0
 
sirbountyCommented:
Thanx for the grade! :^)
0
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.

All Courses

From novice to tech pro — start learning today.