PsFile - CMD
Overview
PsFile
is a command-line tool developed by Sysinternals, available as part of the Windows Sysinternals suite. This utility allows users to view and close files that are opened remotely via a network share. It is useful for administrators who need to manage file access across shared resources and can be effective in environments where file sharing is critical, such as servers that host shared folders.
Syntax
The basic syntax for using the PsFile
command is as follows:
psfile.exe [[\\computer [-u user] [-p passwd]] [[id | path] [-c]]]
Parameters:
\\computer
– Specifies the computer to list or manipulate files. If omitted, the local computer is used.-u user
– Optional. Specifies the username to use when connecting to the remote computer.-p passwd
– Optional. Specifies the password for the user account.id
– Specifies the unique identifier of the file to close.path
– Displays files opened at the specified path.-c
– Closes the file specified by the identifier.
Options/Flags
-u
: This option is used to provide the username for authentication on the remote machine. It helps in scenarios where different permissions are required.-p
: Accompanies-u
to provide the password for the specified user. Ensure this is used securely, especially in scripts.-c
: Closes an opened file specified by its file identifier. This is particularly useful to free up a file locked by a network user.
Examples
-
Viewing Open Files on a Local Machine
psfile.exe
This command lists all files opened remotely on the local computer.
-
View Files Opened from a Specific Path
psfile.exe \\server\share
Displays all files that are opened from the network share specified.
-
Close a File using its Identifier
psfile.exe 1234 -c
Closes the file with the identifier 1234.
Common Issues
- Access Denied: When trying to close a file, you might encounter an “Access Denied” error. Make sure you have adequate permissions, or use the
-u
and-p
options to provide credentials with sufficient rights. - Network Delays or Failures: Connections to remote machines can fail or timeout, particularly in high-latency environments. Ensure network stability and consider using retries in scripts.
Integration
PsFile
can be combined with other commands for powerful administrative tasks. For example:
for /f "tokens=1" %i in ('psfile.exe ^| find "D:\shared\important.doc"') do psfile.exe %i -c
This script searches for and closes all remote connections to “important.doc” on a network share.
Related Commands
- PsExec: Execute processes remotely.
- PsList: List detailed information about processes.
- Net File: Windows native command similar to
PsFile
, used to list or close shared files.
For additional information and updates, refer to the Sysinternals PsFile page.