Solved

Disconnect All Users From Share With VB.NET?

Posted on 2004-09-10
8
514 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

22 Experts available now in Live!

Get 1:1 Help Now