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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disconnecting session.

Status
Not open for further replies.

Targol

Technical User
Sep 13, 2002
908
FR
I'm trying to disconnect all sessions made from clients to my server. Just like doing in commandline a "Net Session //clientName /delete" for all "clientname".

I already tried the old ".bat" method :
- Wscript.run of "Net Session > myfile.txt"
- Read "myfile.txt" after to extract the stations names
- For each stations names : Wscript.run of "Net Session \\stationName /delete"

The problem is that the bat redirecting with a ">" char doesn't work in Wscript.


I've found the NetSessionDel Api
But an Api can't be directly called from vbs and I don't want to use an OCX or dll because of deployement.

So, if someone has got an idea
- either to correctly redirect the stdout in run method of Wscript object.
- or to delete sessions in vbs in a "cleaner" method,
that would be amazing, wonderfull, giga top wizz !!! Water is not bad as long as it stays out human body ;-)
 
u dont need to do it in vbscript:
i've never used net session b4 but you should be able to do

c:\>for /f %a in ('net view ^| find "\\" ') do net session %a /delete

at the cmd prompt ===============
Security Forums
 
I'm sorry to contradict but I need to do it via VBS as its feature has to be done into an SMS process that will run at night. I don't want to wake up at 2h00 AM just to go to work to type a command-line and go back to bed [Morning].

By the way, i'm going to try if your command line works if I use it in a WScript.run. Water is not bad as long as it stays out human body ;-)
 
ok. i see. wscript.run should work.

if u were to do c:\net view | find "\\"
you should get a list of computers on your network

the for /f loop takes each line of the net view find, assigns it to %a and thus feeds it
into net session %a /delete

the ^ is cos u need to escape the | char.
if you ever put the code in a .bat file you have to change %a to %%a ===============
Security Forums
 
Something else you could do is centrally locate a dll or ocx on a common network share. This could then be registered and unregistered (via the script) by any computer with access to that share without actually being depolyed to that computer.

Dana Hallenbeck
 
Thanx to both.
I tried browolf solution but even if it works ok in command line, the same problem than redir (with ">") seems to happen in wscript.run ("file not found" error or something like this).
So I took an intermediate solution near Dana one : creating a VB exe that calls the API needed and that I call from my VBS.
Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top