OpenFiles PowerShell command doesn't work as described in Microsoft Docs

Gab 21 Reputation points
2022-04-06T18:27:07.133+00:00

Introduction:
I need help with OpenFiles, which also comes with Windows 10 Pro.

Situation:
I enabled the local mode as described here https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/openfiles and I can see all local open files as expected. The /disconnect argument however doesn't work with the local files. Whenever I try to terminate a connection with openfiles /disconnect /id ID of handle nothing happens, there's no output (even if the ID is invalid) and if I list all open files again, nothing happened.

Computer details:
My PC on which I'm trying to do this, is running Windows 10 Pro, Version 21H1, Build 19043.1586. I also installed a fresh copy of Windows 10 Pro on a virtual machine to see, if this is an issue related to my install, and on a fresh Windows 10 Pro, Version 21H2, Build 19044.1288 I'm also facing this issue. Didn't test on Windows 11 as I'm not interested in Win11.

Solutions I tried:
-Fresh copy of Windows
-Restarting computer
-Using PowerShell as an administrator (obviously)
-Adding a /local behind the /disconnect, which granted a syntax error

Microsoft Windows Customer Support brought me here, I hope you can help me here.

Best regards,
Gab

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2022-04-07T13:25:11.797+00:00

    Openfiles only disconnect remotely opened files.

    https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc732490(v=ws.11)

    openfiles /disconnect
    Enables an administrator to disconnect files and folders that have been opened remotely through a shared folder.

    For local files you can use handle or process explorer.

    https://learn.microsoft.com/en-us/sysinternals/downloads/handle

    https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer

    Those tools do not need "openfiles /local on", so you can turn that off.


1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,916 Reputation points
    2022-04-07T12:52:55.59+00:00

    Hi @Gab

    Administrator privileges are required for the openfiles command to work as expected.

    Please try the following:

    Right-click the command prompt entry and select Run as administrator from the context menu. Enter openfiles and hit enter to run the command on the system. Description: Enables an administrator to list or disconnect files and folders that have been opened on a system. /Disconnect Disconnects one or more open files.

    Openfiles can do a server direct. You don't have to run it remotely.

    From Help openfiles /query /?

    OPENFILES /Query /S system /U username /P password /NH

    I hope this answers your question.

    Thanks.

    --
    --If the reply is helpful, please Upvote and Accept as answer--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.