×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBS If Err Clear

VBS If Err Clear

VBS If Err Clear

(OP)
Hi, im having an issue with the below. It runs ok however, what I would like it to do is if an error is found with connecting to a computer from the list specified, output the error but continue onto the next machine in the list. What is happening is it comes across a machine, reports the error, but then also reports the files not present from the previous remembered machine. The error from this machine will also create an error onto the next machine in the list when this one connects ok (Hope this makes Sense?)

On Error Resume Next
Set objfso = CreateObject ("Scripting.FileSystemObject")
Set computerList = objfso.OpenTextFile ("C:\Scripts\computerList.txt", 1)
Set outputList = objfso.OpenTextFile ("C:\Scripts\outputList.txt", 8, True)
strFolder = "\AppData\Local\FolderName"
Do While Not computerList.AtEndOfStream
strComputer = computerList.ReadLine
set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "")

if Err.Number <> 0 then
outputList.WriteLine (Now) & vbTab & strComputer & vbTab & "Error connecting to specified computer: " & err.description
Err.Clear
End If

For Each objFolder In objFSO.GetFolder("\\" & strComputer & "\C$\Users\").SubFolders
strUsername = objfolder.Name

If objFSO.FolderExists("\\" & strComputer & "\C$\Users\" & strUsername & strFolder) Then
Set strFolderPath = objFSO.GetFolder("\\" & strComputer & "\C$\Users\" & strUsername & strFolder)
objFSO.DeleteFolder(strFolderPath)
outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files deleted"
Else
outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files not Present"
End If
Next
Loop

The Computerlist file contains machines names

The output of the log file is below, machine1 and machine3 are online, machine2 is offline:-

29/01/2016 12:21:33 machine1:user1 files not Present
29/01/2016 12:21:33 machine1:user2 files not Present
29/01/2016 12:21:33 machine1:user3 files not Present
29/01/2016 12:21:33 machine1:user4 files not Present
29/01/2016 12:21:33 machine1:user5 files not Present
29/01/2016 12:21:33 machine1:user6 files not Present
29/01/2016 12:21:33 machine1:user7 files not Present
29/01/2016 12:21:33 machine1:user8 files not Present
29/01/2016 12:21:33 machine1:user9 files not Present
29/01/2016 12:21:34 machine1:user10 files not Present
29/01/2016 12:21:34 machine1:user11 files not Present
29/01/2016 12:21:34 machine1:user12 files not Present
29/01/2016 12:21:34 machine1:user13 files not Present
29/01/2016 12:21:55 machine2 Error connecting to specified computer: The remote server machine does not exist or is unavailable
29/01/2016 12:22:38 machine2:user13 files not Present
29/01/2016 12:22:38 machine3 Error connecting to specified computer: Object not a collection
29/01/2016 12:22:38 machine3:user1 files not Present
29/01/2016 12:22:38 machine3:user2 files not Present
29/01/2016 12:22:38 machine3:user3 files not Present
29/01/2016 12:22:38 machine1:user4 files not Present
29/01/2016 12:22:38 machine3:user5 files not Present
29/01/2016 12:22:38 machine3:user6 files not Present
29/01/2016 12:22:38 machine3:user7 files not Present
29/01/2016 12:22:38 machine3:user8 files not Present
29/01/2016 12:22:38 machine3:user9 files not Present

Thanks

RE: VBS If Err Clear

What about this:

If Err.Number <> 0 then
  outputList.WriteLine (Now) & vbTab & strComputer & vbTab & "Error connecting to specified computer: " & err.description
  Err.Clear
Else
  For Each objFolder In objFSO.GetFolder("\\" & strComputer & "\C$\Users\").SubFolders
    strUsername = objfolder.Name

    If objFSO.FolderExists("\\" & strComputer & "\C$\Users\" & strUsername & strFolder) Then
      Set strFolderPath = objFSO.GetFolder("\\" & strComputer & "\C$\Users\" & strUsername & strFolder)
      objFSO.DeleteFolder(strFolderPath)
      outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files deleted"
    Else
      outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files not Present"
    End If
  Next
End If 

combo

RE: VBS If Err Clear

(OP)
Pefect, works a treat, just needed a Loop at the End. Thank you for the quick response.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close