Programming Field

Openfiles - DOS/Command Prompt Reference

[Windows XP or later] Displays or disconnects and closes files that are open on the local or remote system.

* Administrator privileges are required for operations on the local system.

Syntax

openfiles[.exe] /Query [/S <remote-system> [/U <user-name> [/P [<password>]]]]
    [/FO <output-format>] [/NH] [/V]
openfiles[.exe] /Disconnect [/S <remote-system> [/U <user-name> [/P [<password>]]]]
    {/ID <id> | /A <access> | /O <mode>}
    [/OP <file-name>]
openfiles[.exe] /Local [ON | OFF]
Common options
/S <remote-system>
Specifies the name of the computer (local/remote) to operate on. Provide the IP address or hostname. If omitted, the local computer will be the target.
/U <user-name> [/P [<password>]]
Specifies the login name and password when specifying the computer name. You can specify the domain name for <user-name> (in the format ‘domain\username’). If omitted, the user already connected using commands like "net use" will be used.
For the password, if you omit the entire ‘/P [<password>]’ part, no password is set. If you specify only ‘/P’ without specifying ‘<password>’, a prompt will be displayed, prompting the user to enter the password (the entered password in this prompt will be displayed as ‘*’ characters).
/Query
Displays a list of open files. If the ‘/S’ option is not specified and the ‘maintain objects list’ flag for tracking locally open files is enabled, the list of locally open files will also be displayed.
/FO <output-format>
Specifies the format for outputting to the screen. The three available values are as follows. If ‘/FO’ is omitted, it defaults to ‘TABLE’.
ValueMeaning
TABLEOutputs in a pseudo-table format. Multiple files can be displayed side by side, but if ‘/V’ is specified, it may cause the display to be distorted due to using a wider width, exceeding the default command prompt width.
LISTDisplays information in a bullet-point-like format for each file. This improves readability but may increase the output volume. Note that when specifying LIST, the ‘/NH’ option cannot be used.
CSVOutputs in CSV format. This is useful when you want to analyze the output, such as passing it to the For command.
/NH
Does not output headers when displaying in TABLE or CSV format.
/V
Output detailed information. Specifically, for files normally opened remotely, the output includes ‘ID’, ‘Access (User)’, ‘Type’, and ‘Open File’. When specifying /V, in addition to these, ‘Hostname’, ‘Lock Count’, and ‘Open Mode’ are also included in the output.
/Disconnect
Forcefully disconnects files that are open remotely.
Either /ID, /A, or /O must be specified (it is possible to combine multiple options).
* Disconnecting locally open files is not possible.
/ID <id>
Specifies the ID of the open file (only one can be specified). The ID is listed in the list obtained with the /Query option. If ‘*’ is specified, all files are targeted.
/A <access>
Specifies the access name of the open file (all files matching the access name specified in <access> will be disconnected). The access name is usually the username. If ‘*’ is specified, all access names are targeted.
/O <mode>
Specifies the open mode of the open file. <mode> will be one of ‘Read’, ‘Write’, or ‘Read/Write’. If ‘*’ is specified, all modes are targeted.
/OP <file-name>
Specifies the path name of the open file (this path name is usually the path name on the target computer). Only files with a fully matching path name will be disconnected. If ‘*’ is specified, all files are targeted.
/Local [ON | OFF]
Sets the flag for tracking locally open files, ‘maintain objects list’, to either enable or disable. When set to ON, you can display a list of locally open files using Openfiles, but there may be a slight decrease in system performance. Changes to the settings take effect after a system restart.
If you execute ‘openfiles /local’ without specifying ON/OFF, it will output the current configuration status.

Details

By using Openfiles, you can check which user has opened files shared over the network and forcibly disconnect (close) files that are open for maintenance or troubleshooting purposes. Enabling ‘maintain objects list’ (by using commands like ‘openfiles /local on’) allows you to also check the status of locally opened files by local applications (but you cannot disconnect them).

Note that administrative privileges are required for operations on the local system. However, when targeting a remote system (using /S), you can leverage the permissions of a specified user with the /U option. Therefore, it is not always necessary to run Openfiles in a session with administrative privileges.

Samples

Sample 1

openfiles /query /v

Outputs detailed information on the open status of files shared over the network on the local system.

Sample 2

openfiles /disconnect /s myserver /u LogOperator /p /id * /op "Y:\Logs\access_log"

Disconnects all connections that have opened the ‘Y:\Logs\access_log’ file on the ‘myserver’. If you know the specific file you want to close, and you are aware of the file's remote system path, you can narrow down the file you want to disconnect by specifying ‘/id *’ and using the /OP option.

Note that in this command line, operations are performed while logged in as the ‘LogOperator’ user. The password for this user will be entered on the prompt when it is displayed.