Solved

Disconnect All Users From Share With VB.NET?

Posted on 2004-09-10
8
511 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now