How can I call the Openfiles.exe (which is on the server 2008 file server) remotely from a computer to see which files are open by the users? I also need to have it login as the domain admin user in the parameters.
-
possible duplicate of [How to remotely execute a command via a batch file?](http://stackoverflow.com/questions/12430049/how-to-remotely-execute-a-command-via-a-batch-file) – Zam May 09 '15 at 22:32
7 Answers
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
-
Yes but I need to run it from the user's workstation not the server. – user3314399 May 11 '15 at 02:48
-
User needs to see who has the file open on the file-server on occasional basis. – user3314399 May 11 '15 at 02:52
-
Why can't they run their own copy? They have a copy too. But they can run any copy they want from any server. `\\server\share\windows\openfiles.exe` – May 11 '15 at 02:57
-
So a user from a workstation (windows 7) can run this command from the command prompt which would trigger the file server and would show how has what file open on the shared drives? – user3314399 May 11 '15 at 03:04
-
They will see what they have permission to see what they are allowed to. But they can specify a different username/password if they wish. `openfiles /s servername`. – May 11 '15 at 03:07
-
What would be the correct synatx to specify a username and password? – user3314399 May 11 '15 at 03:18
-
1It's in my answer. The general form is `username@domain` or `domain\username`. – May 11 '15 at 04:13
-
Thank you I got it. Is there anyway I can specif in the command line to only show open files in a particular folder? – user3314399 May 11 '15 at 04:32
-
1
-
I tried this but it didn't work: c:\Windows\System32>openfiles.exe /query | findstr /i /E:"/FolderName/FolderNAme2" /S ServerIP / U ServerName\administrator /P Passwprd /FO csv /v >C:\test\test.csv – user3314399 May 11 '15 at 20:07
-
1`openfiles.exe /query /S Serenity /U "Serenity\David Candy" /p "Pass" /FO csv /v | findstr /i /C:"Documents" > C:\test\test.csv` – May 11 '15 at 22:18
-
1Note `/c:"documents"` c: is NOT a drive letter. Don't change it. Type `findstr /?` – May 12 '15 at 01:30
-
@trigger - is there a way to get a list of the files for all users *but* the admin user, so I could close the open files? let's say I want to exclude 'devadmin' user from the list - but want to find and close all other files... – Oleg Ivanov Apr 27 '16 at 11:27
A way to do it in PowerShell and to allow for searching would be with this small function.
function Get-OpenFiles {
cls
openfiles /query /s $args[0] /fo csv /V | Out-File -Force C:\temp\openfiles.csv
$search = $args[1]
Import-CSV C:\temp\openfiles.csv | Select "Accessed By", "Open Mode", "Open File (Path\executable)" | Where-Object {$_."Open File (Path\executable)" -match $search} | format-table -auto
Remove-Item C:\temp\openfiles.csv
}
It allows you to call Get-OpenFiles Server Filename
and it will show you the results. The caveat is that you have a folder called C:\temp.
So if I do Get-OpenFiles TestServer Hardware
I get the below.
Accessed By Open Mode Open File (Path\executable)
----------- --------- ---------------------------
NFDJWILL Read N:\Network Services\Documentation\Hardware.xlsx
NFDJWILL Write + Read N:\Network Services\Documentation\Hardware.xlsx
NFDJWILL Read N:\Network Services\Documentation\Hardware.xlsx

- 314
- 1
- 6
- 25
-
3Note: You can do this without using a temp file by piping your openfiles command into ConvertFrom-CSV then piping into Select like so: openfiles /query /s blah /fo csv /V | ConvertFrom-Csv | Select "Open Mode" – Preston Apr 14 '17 at 01:41
Here is a solution without creating temporary files.
function Get-OpenFile
{
Param
(
[string]$ComputerName
)
$openfiles = openfiles.exe /query /s $computerName /fo csv /V
$openfiles | ForEach-Object {
$line = $_
if ($line -match '","')
{
$line
}
} | ConvertFrom-Csv
}
Get-OpenFile -ComputerName server1

- 2,125
- 4
- 30
- 40
how to run application remotely by using Power Shell https://technet.microsoft.com/en-us/library/dd819505.aspx
your PS or BAT script will be:
openfiles.exe > c:\temp\openfiles.txt
of course better use different output folder and file name.
Alternative way: https://technet.microsoft.com/en-ca/sysinternals/bb897553.aspx -- PsExec -- PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

- 2,880
- 1
- 18
- 33
You can use a remote delegated powershell session for this.
Use Delegated Administration and Proxy Functions
You can delegate the admin credentials in RunAs setting of the session configuration, and constrain the session to only being able to run the openfiles.exe. Then you can assign permission to use to session to selected groups or users. This enables you to let people run cmdlets or programs that require domain admin authority, without giving them the domain admin credentials.

- 66,130
- 7
- 114
- 135
No need to create a CSV file and have to remove it later, or be concerned about its' size.
openfiles /s MyFileSrv /query /fo CSV /v /u admin1 /p myPass | convertfrom-csv |?{$_.'Open File (Path\executable)' -match "MyFolder"} |select 'Accessed By', 'Open Mode', 'Open File (Path\executable)
Accessed By Open Mode Open File (Path\executable)
----------- --------- ---------------------------
robinsonl Write + Read D:\Dept\MyFolder
smithd Read D:\Dept\MyFolder\info
If you're using powershell 1.0 then add |select -skip 8| before the convertfrom-csv portion.

- 756
- 6
- 3