Remotely close open shared files

5

1

I have a Windows 7 computer that is hosting some files in my network. Sometimes a file (usually an Office document) is stuck in the open state even after a user has finished editing it. What I do to resolve this is to go to Computer Management > Shared Folders > Open Files and close the connection to the culprit file.

However, I always have to do this by remote controlling the host computer. Is there a faster way to accomplish this? I'm open to anything that can help me speed up the process (batch, powershell, remote MMC, etc).

What I've Tried:

I've tried using Remote MMC from my workstation into the host, but when I try to open System Tools > Shared Folders > Open Files I get error You do not have permissions to see the list of files opened by Windows clients.

Edit:

While remote commands are great, and I'd be open to using them, I need a way to both list the files, identify which one I need closed, and close it in relatively the same amount of time that it would take to use the MMC snap-in to do it through the GUI.

Moses

Posted 2013-09-11T15:41:23.217

Reputation: 10 813

check out my comment on Keltari's answer. Net file is your friend. ;) – Ƭᴇcʜιᴇ007 – 2013-09-11T16:00:13.053

Answers

6

From this TechNet article :

To close an open shared file or folder by using the Windows interface:

  1. Open Computer Management.
  2. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Yes.
  3. Go under the Action menu and click Connect to another computer . . .
  4. In the console tree, click System Tools, click Shared Folders, and then click Open Files.
  5. Do one of the following:
  6. To close all open files and folders, on the Action menu, click Disconnect All Open Files.

  7. To close a specific file or folder, in the Results pane right-click the file or folder name, and then click Close Open File.

  8. To disconnect multiple open files or folders, press the CTRL key while clicking the file or folder names, right-click any one of the selected files or folders, and then click Close Open File. This closes the selected files or folders.

To close an open shared file or folder by using a command line

  1. To open an elevated Command Prompt window, click Start, point to All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator.
  2. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Yes.
  3. Type:

net file <ID> /close

For example, to close an open file identified as myfile_id, type:

net file myfile_id /close

Keltari

Posted 2013-09-11T15:41:23.217

Reputation: 57 019

1Thanks, but I'm trying to do this remotely from another workstation. The net file command would be useful, but without the file IDs on hand, it would be tough to put it into practice. – Moses – 2013-09-11T15:50:46.733

you can always use psexec to issue remote commands http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

– Keltari – 2013-09-11T15:51:42.810

I know how to execute a command remotely, but without the list of files, how am I going to execute the remote command to successfully close one? – Moses – 2013-09-11T15:53:46.587

net file without any arguments lists the open files and their IDs. So you could use PSExec to run Net File to get a list on the remote computer, and then use it again with Net File <id> /Close. Or perhaps just use PSFile, since it can work with remote computers inherently. – Ƭᴇcʜιᴇ007 – 2013-09-11T15:58:04.373

@techie007 I just discovered that, thank you! Added my own answer to combine both commands. – Moses – 2013-09-11T16:03:59.183

@Keltari now I just need to get it to work in ubuntu! :) – Moses – 2013-09-11T16:05:19.877

2

I was able to get a viable solution after expanding on the bottom section of Keltari's answer.

I can execute net file <ID> /close to terminate a connection to a file, but without a list of files that are currently open, the command is useless.

By simply executing net file, it will print a list similar to what is listed in the GUI for the MMC Shared Files Snap-in. It lists the File ID, File Path, Username, and # of locks on the file.

Using this information I can follow up with the net file <ID> /close command to close the file.

To do this remotely, I can use Psexec as Keltari suggested. Or PsFile as suggested by the venerable techie007 :)


Alternative solution:

I found a lovely little piece of freeware called ShareWatch that can remotely view shares. This is a nice little tool as it lists not only the user and the file they have open, but the IP of that user as well. You can also remotely close shares.

Moses

Posted 2013-09-11T15:41:23.217

Reputation: 10 813

2To reiterate - if you're going to be getting PSExec involved, just use PSFile instead - reduce a couple steps. :) – Ƭᴇcʜιᴇ007 – 2013-09-11T16:27:43.313

@techie007 Thanks, I read too fast :) – Moses – 2013-09-12T17:17:07.140