Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disconnect sessions with files open? 1

Status
Not open for further replies.

CRMcM

Technical User
Dec 7, 2002
36
0
0
US
Is it possible to disconnect users that have shared files open with a vbscript? I would like to disconnect all open files prior to nightly backup running. Thanks for any help.
 
CRMcM,

If you control the Server, as it appears you do, you can use a combination of:

In Microsoft Windows NT, use User Manager for Domains to establish logon hours. In Windows 2000, use Active Directory Users and Computers, via a snap-in for Microsoft Management Console (MMC). Logon hours can be applied on either a permit or deny basis.

When a user's logon hours expire, the user can continue to work on the workstation but cannot access any network resources except the resources that are already open, such as the shares that the user is accessing.

In Windows NT, you can disconnect users from all network resources when their hours expire by choosing Policies from the User Manager for Domains, Account, and then Forcibly Disconnect Remote Users From The Server When Logon Hours Expire at the bottom of the Account Policy dialog box.

Purportedly the following site has a script detailing how to disconnect your users, but costs $$.

Hope this helps.
DougCranston
 
No. I tried limiting thier hours but that didn't close open shares. I want to close them to allow the backups to run. Thanks for trying and if you have more suggestions I would like to see them.
 
CRMcM,
Force User Logoff w
hen Time Expires

force logoff for all users

Disconnecting All Users from a Server
Can I use an automated procedure to disconnect all users from my server at a certain time each day?
This requires a membership as noted earlier, $129 for a year.

Hope this works for you.
DougCranston
 
If you limit their hours they can't open new files. Then the problem is getting the existing files closed successfully, right?

So it sounds like what you want is a script that will look up these open files and do:
Code:
NET FILE nnn /CLOSE
... on each of the ones that show up as open.

So wouldn't it work to have a script run
Code:
NET FILE
, grab the report, then scan through the report and do the
Code:
NET FILE nnn /CLOSE
for each such open file reported?

Yes, if something like Windows Explorer has folders open it will just try to reopen them again. Isn't that where the policy to limit their hours of use comes in?
 
dilettante,

That was brilliant. I saw NET references but none for file when I was trying get him an answer. Only NET SHARE and that was too radical.

Good one.
DougCranston
 
Thanks dougcranston.

It just so happened that I ran across NET FILE nnn /CLOSE while looking for something else a couple days ago.

I wrote a nice VBScript to do it too, but it is sort of thrash-o-rama as it runs the NET FILE and then each NET FILE nnn /CLOSE via WScript.Exec. This means each run pops up a separate command window briefly: flicker, flicker, flicker! I used Exec because it avoids having to create temporary files containing redirected output. This has its own drawbacks though, I guess.


But this isn't a new problem at all, and it turns out that in some cases a CMD/BAT file has VBScript beat hollow!

NET FILE gives back a list of open files and a final "The command completed successfully." line. At the head of each response line is the file ID number. So at a comand prompt you can just type:
Code:
for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close
This works great, except you get an error on the "The" at the head of the final line of response from NET FILE. Just ignore the final error!

BTW, from a CMD/BAT file, the syntax must be:
Code:
for /f "skip=4 tokens=1" %%a in ('net files') do net files %%a /close
I can't take any credit for this one. Found it after a little digging today at:

 
Anyone have any way to do this with WSH/VBscript?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top