Solved

Disconnect All Users From Share With VB.NET?

Posted on 2004-09-10
8
530 Views
Last Modified: 2010-04-23
Hello,

I need a process that will automatically disconnect all users connected to a share on a server when it is executed.  Ideally, I would like to do this with .NET.

I need this process to have the same functionality as the following manual process:

-On Windows Server 2003, I go to Computer Management --> Shared Folders --> Sessions, right click "sessions" and then choose "Disconnect all sessions".

Alternatively, this can be done at a command prompt with:

NET SESSION /DELETE /y

I need to automate this to run automatically at a specified time.

Thanks!
0
Comment
Question by:mjrogan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 8

Expert Comment

by:wguerram
ID: 12123821
I tied using this API: NetSessionDel

But i never could it get to work:

You can do this:

        Dim s As New System.IO.StreamWriter("C:\delshared.bat")
        s.Write("NET SESSION /DELETE /y")
        s.Close()
        Shell("C:\del.bat", AppWinStyle.Hide)
        Kill("C:\delshared.bat")
0
 

Author Comment

by:mjrogan
ID: 12132332
Thanks.  The filename in the fourth line should be delshared.bat as well, right?

If so, I am getting the following when I run it:

"The batch file cannot be found"

What could be wrong here?

Thanks again!
0
 

Author Comment

by:mjrogan
ID: 12132391
Also, if I comment out the last line, it runs without error, but the command window reamins open.  Once I uncomment the last line, however, the batch file not found error returns.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:wguerram
ID: 12136825
Sorry, it should be this way

        Dim s As New System.IO.StreamWriter("C:\delshared.bat")
        s.Write("NET SESSION /DELETE /y")
        s.Close()
        Shell("C:\delshared.bat", AppWinStyle.Hide) 'Execute the bat file
        Kill("C:\delshared.bat")   'Delete the file from the disk


I tried and it works fine.
0
 

Author Comment

by:mjrogan
ID: 12141876
The first time it is executed, it does run successfully.  However, any subsequent time that it is executed, it returns the following:

The batch file cannot be found.
0
 

Author Comment

by:mjrogan
ID: 12141905
Or it returns this:

'C:\delshared.bat' is not recognized as an internal or external command, operable program or batch file.
0
 
LVL 8

Accepted Solution

by:
wguerram earned 500 total points
ID: 12143051
I tried this and it works:

Shell("NET SESSION /DELETE /y")
0
 

Author Comment

by:mjrogan
ID: 12228514
That worked, thanks!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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