Tool for closing open files on a smb network share (MS server 2012) with non-admin user rights

AlexSper 1 Reputation point
2021-05-20T12:57:36.297+00:00

Hello everyone
I need to implement a service for closing open files on a network drive. I know about the possibility of closing from the server console or PS scripts (Close-SmbOpenFile), but all this does not suit me, since the service must be available to a certain group of users who do not have administrator rights on the file server. I think , I need to write my own application that will run on the server and will have the rights to work with files, and interact with the user in some way via the web-page on iis or some scripts. I ask for advice on how to start solving the problem, what to use. Can someone tell me good examples, cases, exp. Thx!

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,127 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,249 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Timon Yang-MSFT 9,571 Reputation points
    2021-05-21T02:32:42.377+00:00

    How do we judge whether a file that is being opened has been forgotten to close or is being used?

    If another user is using it, it does not seem appropriate to force it to be turned off.

    However, if you really want to do this, you might consider using Process.Kill().

    Just be aware that this method will not be available if the program is placed in the user's local machine instead of the Windows server, because this method can only work on processes running on the local computer.

    Please also refer to the following link, which may help you.

    Force close an open network file on Windows Server 2012 with C#

    Closing Open Files using C#


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Cheong00 3,471 Reputation points
    2021-05-21T02:51:07.33+00:00

    The recommended way to deal with you concern for non-admin user is to ask the users to log-off each time they don't use the computer. No need to write an App for that purpose.

    Since the Lanman on Windows lives in Explorer.exe, as soon as it dies, the remote SMB server will detect connection lost and close the session along with all opened files with it.

    If you really want to write a web application for the purpose, just use impersonation to run your WMI cmdlet as one of the administrators and revert when done.

    1 person found this answer helpful.