Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

VBScript Error help


  • Please log in to reply
4 replies to this topic

#1 doomgiver13

doomgiver13

  • Members
  • 103 posts
  • OFFLINE
  •  
  • Local time:02:10 AM

Posted 24 March 2010 - 11:54 AM

The following is a script i'm using to push updated files over my network. I keep getting an error that says "can't find path". Is there any way that when I run this, I can find out which loop iteration it is failing on? I could go to the reference file and just start changing computer names but if I can somehow ID the fail point, it could be useful in troubleshooting other scripting problems I may encounter. Also, is it possible to have the script skip the errored iteration and move on to the next loop?

[codebox]Const ForReading = 1
Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt")

Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
strRemoteFile = "\\" & strComputer & "\C$\PathToFolder"
objFSO.CopyFile "C:\transferring.file", strRemoteFile, OverwriteExisting
Loop
[/codebox]
If you truly live by the sword, it only stands to reason that someone has to die by it.

BC AdBot (Login to Remove)

 


#2 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:10 AM

Posted 25 March 2010 - 03:30 PM

Hello doomgiver.

You could catch and handle the error. Take a look at this article.

For example..
Const ForReading = 1
Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt")

Do Until objFile.AtEndOfStream
	strComputer = objFile.ReadLine
	strRemoteFile = "\\" & strComputer & "\C$\PathToFolder"
	On Error Resume Next
	objFSO.CopyFile "C:\transferring.file", strRemoteFile, OverwriteExisting
	If Err.Number<>0 then'Error has occured
		msgbox strComputer & " " & Err.Description
		Err.Clear
	End If
	
	On Error Goto 0
	

Loop

In the example, the computername is just being printed, but you could easily change it to write to a log or take other action.

Hope that helps,
The Panda

#3 doomgiver13

doomgiver13
  • Topic Starter

  • Members
  • 103 posts
  • OFFLINE
  •  
  • Local time:02:10 AM

Posted 26 March 2010 - 03:10 PM

Thanks a bunch Panda!!! I'll do some testing... But that looks like it should work!
If you truly live by the sword, it only stands to reason that someone has to die by it.

#4 doomgiver13

doomgiver13
  • Topic Starter

  • Members
  • 103 posts
  • OFFLINE
  •  
  • Local time:02:10 AM

Posted 29 March 2010 - 10:45 AM

The error handling works beautifully. Thanks again.

Edited by doomgiver13, 29 March 2010 - 10:55 AM.

If you truly live by the sword, it only stands to reason that someone has to die by it.

#5 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:10 AM

Posted 29 March 2010 - 04:23 PM

No problem :thumbsup: .

The Panda




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users