Solved

Script to copy URL link to multiple computers

Posted on 2010-09-23
9
586 Views
Last Modified: 2012-05-10
I am creating a script to copy a URL shortcut to about 50 pcs, I would keep the list names in a txt file -->  "CopyFilesPcList.txt"

I get an error
LINE 15..... Unterminated string constant
Const ComputersList = "C:\sysadmin\CopyFilesPcList.txt"

Const SourceFile = "C:\sysadmin\Isolations.url"

Const TargetFolder = "C:sysadmin\"

Const ReportFile = "C:\sysadmin\CopyFilesLog.txt"

 

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objFile : Set objFile = objFSO.CreateTextFile (ReportFile)

arrComputers = Split(objFSO.OpenTextFile(ComputersList).ReadAll, vbNewLine)

 

For Each PC in arrComputers

  objFile.WriteLine "Attempting copy to " & PC

  On Error Resume Next

  objFSO.CopyFile SourceFile, "\\" & PC & "\" & Replace(TargetFolder, ":\","$\")

  If Err.Number <> 0 Then

    objFile.WriteLine vbTab & "Failed to copy to " & PC"

  Else

    objFile.WriteLine vbTab & "File successfully copied to " & PC

  End If

  On Error Goto 0

Next

 

objFile.Close

Open in new window

0
Comment
Question by:epicazo
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 4

Assisted Solution

by:Cristi_E
Cristi_E earned 125 total points
ID: 33747595
Hi epicazo,
Try to replace the line 15 with this one:
objFile.WriteLine vbTab & "Failed to copy to PC"
and line 17 with this one:
objFile.WriteLine vbTab & "File successfully copied to PC"
I don't see any PC variable so you can treat it as text.


I hope it will help!
All the best!
0
 
LVL 4

Expert Comment

by:Cristi_E
ID: 33747682
Now i saw it on line 10 !!!!!!!
So you just need to change the line 15 with this one:
    objFile.WriteLine vbTab & "Failed to copy to " & PC

Thanks!
0
 
LVL 11

Expert Comment

by:TheGorby
ID: 33748101
FYI anytime you get that 'Unterminated string constant ' error, it usually means you've got an extra or missing quote mark on one of your strings somewhere.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33749927
Cristi_E is right, you just had an extra quote on the end of line 15.   Removing that will solve your problem.

FYI, you're also missing a slash in the target folder.  This line
Const TargetFolder = "C:sysadmin\"

should be
Const TargetFolder = "C:\sysadmin\"

Regards,

Rob.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:epicazo
ID: 33755863
I made the corrections, but for some reason I get an error in my log

Attempting copy to thebest1
      Failed to copy to \\thebest1\C$\Documents and Settings\All Users\Desktop

I do have access to the computer when I type "\\thebest1\C$\Documents and Settings\All Users\Desktop"

Here is my updated code
Const ComputersList = "C:\sysadmin\CopyFilesComputers.txt"

Const SourceFile = "C:\sysadmin\Isolations.url"

Const TargetFolder = "C$\Documents and Settings\All Users\Desktop"

Const ReportFile = "C:\sysadmin\CopyFilesLog.txt"

 

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objFile : Set objFile = objFSO.CreateTextFile (ReportFile)

arrComputers = Split(objFSO.OpenTextFile(ComputersList).ReadAll, vbNewLine)

 

For Each PC in arrComputers

  objFile.WriteLine "Attempting copy to " & PC

  On Error Resume Next

  objFSO.CopyFile SourceFile, "\\" & PC & "\" & Replace(TargetFolder, ":\","$\")

  If Err.Number <> 0 Then

    objFile.WriteLine vbTab & "Failed to copy to \\"  & PC & "\" & Replace(TargetFolder, ":\","$\")

  Else

    objFile.WriteLine vbTab & "File successfully copied to " & PC & "\" & Replace(TargetFolder, ":\","$\")

  End If

  On Error Goto 0

Next

 

objFile.Close

Open in new window

0
 
LVL 4

Expert Comment

by:Cristi_E
ID: 33757503
It would be useful to see the error number and description.
Just temporary replace the line 15 with this one and paste back the result:
    objFile.WriteLine vbTab & "Failed to copy to \\"  & PC & "\" & Replace(TargetFolder, ":\","$\") & " --> Number: " & Err.Number & ", Description: " & Err.Description

0
 

Author Comment

by:epicazo
ID: 33758189
hmmm?    what is strange is that I am able to copy/past into that folder..

here is the error:
--> Number: 70, Description: Permission denied
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 125 total points
ID: 33759018
Hi, do you know if the PC is actually on?

Try this. I have added a Ping function.

Oh, and you also needed the trailing slash on the TargetFolder.

Regards,

Rob.
Const ComputersList = "C:\sysadmin\CopyFilesComputers.txt"

Const SourceFile = "C:\sysadmin\Isolations.url"

Const TargetFolder = "C:\Documents and Settings\All Users\Desktop\"

Const ReportFile = "C:\sysadmin\CopyFilesLog.txt"



If Right(TargetFolder, 1) <> "\" Then TargetFolder = TargetFolder & "\"	

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objFile : Set objFile = objFSO.CreateTextFile (ReportFile)

arrComputers = Split(objFSO.OpenTextFile(ComputersList).ReadAll, vbNewLine)

 

For Each PC in arrComputers

	If Trim(PC) <> "" Then

		If Ping(PC) = True Then

			objFile.WriteLine "Attempting copy to " & PC

			On Error Resume Next

			objFSO.CopyFile SourceFile, "\\" & PC & "\" & Replace(TargetFolder, ":\","$\")

			If Err.Number <> 0 Then

				objFile.WriteLine vbTab & "Failed to copy to \\"  & PC & "\" & Replace(TargetFolder, ":\","$\")

			Else

				objFile.WriteLine vbTab & "File successfully copied to " & PC & "\" & Replace(TargetFolder, ":\","$\")

			End If

			Err.Clear

			On Error Goto 0

		Else

			objFile.WriteLine vbTab & PC & " is offline"

		End If

	End If

Next

 

objFile.Close



Function Ping(strComputer)

	Dim objShell, boolCode

	Set objShell = CreateObject("WScript.Shell")

	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)

	If boolCode = 0 Then

		Ping = True

	Else

		Ping = False

	End If

End Function

Open in new window

0
 

Author Closing Comment

by:epicazo
ID: 33774816
thank you all for yor help.  I split the points
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now