?
Solved

VBScript to copy shortcut

Posted on 2008-11-18
8
Medium Priority
?
803 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:georgedschneider
  • 5
  • 3
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22985178
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
 

Author Comment

by:georgedschneider
ID: 22994899
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 22994920
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:georgedschneider
ID: 22995361
What do you mean by splitting?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22995450
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
 

Author Comment

by:georgedschneider
ID: 22996421
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 22996570
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 22997264
Thanx for the grade! :^)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question