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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

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
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
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

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

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
sirbountyCommented:
Thanx for the grade! :^)
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
VB Script

From novice to tech pro — start learning today.