How will I do this in powershell. I like to check which process/application is using the file, so that I can close it.
Thanks.
How will I do this in powershell. I like to check which process/application is using the file, so that I can close it.
Thanks.
You should be able to use the openfiles command from either the regular command line or from powershell.
EDIT:
The openfiles built-in tool can be used for file shares or for local files. For local files, you must turn on the tool and restart the machine (again, just for first time use). I believe the command to turn this feature on is: openfiles /local on
Eg (works on Vista x64):
openfiles /query | find "chrome.exe"
That successfully returns file handles associated with Chrome. You can also pass in a file name to see the process currently accessing that file.
You can do this with the SysInternals tool handle.exe. Try something like this:
PS> $handle = handle
PS> foreach ($line in $handle) {
if ($line -match '\S+\spid:') {
$exe = $line
}
elseif ($line -match 'C:\\Windows\\Fonts\\segoeui\.ttf') {
"$exe - $line"
}
}
MSASCui.exe pid: 5608 ACME\hillr - 568: File (---) C:\Windows\Fonts\segoeui.ttf
...
I try the openfiles command that Garret say. It works flawsless almost for every file that y try... the only files where i can't find a program related are disc images mounted...i have a file mounted with virtual clone drive but doesn't appear in "openfiles /query"...the only way to findit is use the sysinternals software aformention by Keith Hill. It will be nice have a native way to findit.