Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/future4tech/public_html/wp-includes/functions.php on line 6114
OPENFILES.exe – Windows CMD Command - Future4Tech

OPENFILES.exe – Windows CMD Command

Query or display open files, disconnect files opened by network users.

Syntax
      Openfiles.exe /query [/s Computer [/u Domain\User [/p Password]]]
        [/fo {TABLE|LIST|CSV}] [/nh] [/v]

      Openfiles.exe /disconnect [/s Computer  [/u Domain\User [/p Password]]]
         {[/id OpenFileID]|[/a UserName]|[/o OpenMode]} [/se SessionName] [/op OpenFileName]

Key
   /s     The name or IP address of a remote computer. (Do not use backslashes.) default=local computer.

   /u     Run the command with the account permissions of user. Default=current logged on user.

   /p     The password of the user account specified with /u.

   /fo    The format to use for the query output. Valid values are TABLE, LIST, and CSV. Default=TABLE.

   /nh    No column headers in the output. Valid only when /fo = TABLE or CSV.

   /id    Disconnect the file opened with the specified numeric OpenFileID on computer
          Use openfiles.exe /query to learn the file ID.
          The wildcard (*) can be used to disconnect all open files on computer.

   /a     Disconnect all open files that were accessed by user on computer.
          The wildcard (*) can be used to disconnect all open files on computer.

   /o     Disconnect all open files with the specified OpenMode on the computer specified by the /s parameter.
          The OpenMode parameter includes the Read/Write and Read modes.
          The wildcard (*) can be used to disconnect all open files on computer.

   /se    Disconnect all open files that were created by the specified session on computer.
          Wildcards (*) can be used. (the /se option is not available under Windows 7)

   /op    Disconnect the open file that was created with the specified OpenFileName on computer 
          The wildcard (*) can be used to disconnect all open files on computer.

   /v     Display verbose information in the output.

   /?     Help.

Administrator privileges are required to run the OPENFILES command. We can use this fact to detect if the current user is an Admin ( OPEN FILES >nul 2>nul will set %ERRORLEVEL% = 1 if the user is not an administrator.) However this will fail when running under WOWf4t e.g. running a 32-bit installer on a 64-bit system, so an alternative is to use NET SESSION.

Running openfiles.exe from within powershell allows the output to be easily assigned to a variable.

Examples

From the CMD shell:

C:\> openfiles /query /fo list /v
C:\> openfiles /query /s Serverf4t /u F4TDom\FileAdmin /p password1

C:\> openfiles /disconnect /o read/write
C:\> openfiles /disconnect /op "c:\work\finance.xls"
C:\> openfiles /disconnect /s Serverf4t /u F4TDom\FileAdmin /id 5
C:\> openfiles /disconnect /s Serverf4t /u F4TDom\FileAdmin /p password1 /id *

From PowerShell:

PS C:\> openfiles /query
PS C:\> openfiles /query /fo table /nh
PS C:\> $file_list = openfiles /query /s Serverf4t /fo CSV /v /nh
PS C:\> openfiles /query /s Serverf4t /fo CSV /v | ConvertFrom-Csv | Out-GridView

PS C:\> openfiles /disconnect /id 1
PS C:\> openfiles /disconnect /a mike

You may also like...

2 Responses

  1. zoritoler imol says:

    Enjoyed studying this, very good stuff, appreciate it. “The fox knows many things, but the hedgehog knows one big thing.” by Archilocus.

  2. zortilo nrel says:

    I genuinely treasure your work, Great post.

Leave a Reply

Your email address will not be published. Required fields are marked *


Notice: ob_end_flush(): Failed to send buffer of zlib output compression (0) in /home/future4tech/public_html/wp-includes/functions.php on line 5464