Solved

Sometimes Error-message in vbscript (sheduled task)

Posted on 2011-09-15
2
243 Views
Last Modified: 2012-05-12
Hi everyone,

For some time now I have been using a vbscript to automatically close idle sessions to a XP-host in my network. It acts as a FTP-server and people use it a lot to access shared folders. After some open sessions, some clients can't connect anymore to the shared folders. The script cleares the connections of the users which doesn't have any open files.

I have the feeling that the script doesn't work anymore and sometimes an error-message appears. It is actually random when the script runs. I have set this to run every 5 minutes.

I hope you can help me resolve this. I have enclosed the error message on my server and the vbscript.

Thanks in advance!
Set dResources = CreateObject("Scripting.Dictionary")
Set oConnection = GetObject("WinNT://DT_A2O_XW6200_1/LanmanServer")

Set cResources = oConnection.Resources
For Each oResource in cResources
    If Not dResources.Exists(LCase(oResource.User)) Then dResources.Add LCase(oResource.User), 1
Next
Set cResources = Nothing


Set cSessions = oConnection.Sessions
For Each oSession in cSessions
    If Not dResources.Exists(LCase(oSession.User)) Then _
        cSessions.Remove(oSession.Name)
Next
Set cSessions = Nothing

Set oConnection = Nothing
Set dResources = Nothing

Open in new window

Script-error.png
0
Comment
Question by:Silencer001
2 Comments
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 125 total points
ID: 36546207
Hi, it looks like the session has already disappeared the moment you are trying to close it.

You could add some basic error handling by adding "On Error Resume Next" at the begin of your script. That will ignore the error and continue your script.

If you're interested in how may times things go wrong, add some code after the csessions.Remove statement, like writing date,time, session name etc. to a file.

When for some reason, your script stops functioning at all, you'd have to comment out the On Error ... statement to see the errors again.
0
 

Author Comment

by:Silencer001
ID: 36558907
Thanks for the answer gerwinjansen. I just added the "On error resume next" and will see how it goes. I also removed the old sheduled task and made a new one. At the first glance, everything is going good at the moment. Thanks!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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