Removing Remote Locks from UNC Shared Paths
I'm having trouble right now finding a solution for unlocking UNC path files for our deployment scenario. Here is the current situation:
We have multiple file server machines. Our deployment application is setup to deploy from an MSBUILD drop location to a set of target folders (Using defined filters, etc). These file shares are used by many users of the company to run our software. As these users open our software, they create a remote read lock on the files they use.
We have admin accounts to do this (via impersonation) of our deployer. We can also do this manually via remote computer management. The problem comes in when we try to automate the process in our autobuilds.
At our current state, we were trying to use openfiles.exe to read and unlock the files (via /query /s //server /v), parsing the 开发者_运维技巧IDs, then using the ID to remove the lock. The problem we run into is that openfiles.exe returns local file paths vs UNC file paths.
Is there a way to remotely remove a file lock from a server only knowing that file's UNC path (and not knowing it's local path)? We don't necessarly have permission to add applications on the target servers (as there are many), so solutions such as PsExec -> Handle.exe would most likely not work for us.
Thanks in advance for any help! -Corey
I'm pretty sure that you can use WMI to query a Windows computer for a list of its defined shares, which would include the share name and the local path.
Given the strong integration of WMI into PowerShell - and given that PowerShell is much easier to use than raw WMI - it shouldn't be too difficult to write a powershell function that converts a UNC path into a local path for the host machine.
As a starting point, check out PowerShell Scripting - WmiObject Win32_Share:
The purpose of this script is to list shares on a server. In fact, this code will enumerate the shares on any computer.
If you get this working, please share the result!
精彩评论