• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help with a vbs script

Brazen

Diamond Member
I found this script for killing ALL open file sessions:
Set objConnection = GetObject("WinNT://atl-ws-01/LanmanServer")
Set colSessions = objConnection.Sessions

For Each objSession in colSessions
colSessions.Remove(objSession.Name)
Next

but i just want to kill one open file session. I tried doing this:
Set objConnection = GetObject("WinNT://CSVS03/LanmanServer")
Set colSessions = objConnection.Sessions

colSessions.Remove("ADMINISTRATOR\GISS04")
but then I get an error if the session does not exist (which sometimes it won't) and then the scheduled task hangs open.

I thought somehow I could test to see if the session existed with something like this:
Set objConnection = GetObject("WinNT://CSVS03/LanmanServer")
Set colSessions = objConnection.Sessions

if (objSession.Name("ADMINISTRATOR\GISS04")) Then
colSessions.Remove("ADMINISTRATOR\GISS04")
end if
but now I get a compile error saying "Object required: 'objSession'"

Can someone help me out?
 
Put it back to your orignial code.

At the top put:

On Error Resume Next

Then you shouldn't get an error when that session doesn't exist, the code will continue on to completion.
Error handling in vbscript is pretty non-existant so it can be a pain.
 
your compile error of object required: objSession is because you're trying to use something called objSession and in your code snippet you never declare it or set it.
 
Try

Set objConnection = GetObject("WinNT://atl-ws-01/LanmanServer")
Set colSessions = objConnection.Sessions

For Each objSession in colSessions
If objSession.Name = "ADMINISTRATOR\GISS04" Then colSessions.Remove(objSession.Name)
Next
 
Thanks guys, bunker and KB both had good suggestions and it was a toss up but I used bunker's suggest. Works like charm.
 
i didn't think that it was objSessions that was mistyped. i thought that what was missing was a declaration of a different variable named objSession that was meant to be assigned before it was used.
 
Back
Top