NovasTaylor has asked for the wisdom of the Perl Monks concerning the following question:

I seek the following Perl wisdom: I wish to use Perl to force a file lock closed on a Win 2003 file server. Assume I know the server name and complete path to the file in question. I looked at Roth's CloseFiles.pl script but it requires Win32-Lanman that is not compatible with my Perl 5.10 install. My OS is Windows Server 2003 R2. What other paths must I follow? Tim

Replies are listed 'Best First'.
Re: Force Windows File Lock closed?
by John M. Dlugosz (Monsignor) on May 15, 2009 at 20:23 UTC
    Take a look at CloseFiles.pl even though you can't run it. What function does it call in Win32-Lanman? That might be suggestive.

    I think it might be wiser to force the handle closed than to just remove the locks. I know Process Explorer (from Sysinternals) does it. Mark might explain how in one of the articles. It probably involves native NT calls, bypassing the Win32 API layer.

    —John

Re: Force Windows File Lock closed?
by afoken (Chancellor) on May 15, 2009 at 20:45 UTC

    I found this german blog post (Google translation) that links to a freeware tool called UnlockMe. Does that help you?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Force Windows File Lock closed?
by trwww (Priest) on May 15, 2009 at 22:09 UTC

    I looked at Roth's CloseFiles.pl script but it requires Win32-Lanman that is not compatible with my Perl 5.10 install.

    You could always install an older perl in a different location. That could be one path of lesser resistance.

    regards,

Re: Force Windows File Lock closed?
by Marshall (Canon) on May 16, 2009 at 21:01 UTC
    Interesting question. I looked at this and on Windows, there appears to an "Oh" command!
    http://windowsxp.mvps.org/processlock.htm
    So you could get this "OH command!" (Open Handles) thing and find out who is currently using this file, then kill those processes and that will release the locks on the file and then you can delete that file! The idea is not to mess with the Windows file lock yourself, but use kill process to stop everybody who is using that file and then the file is not "locked".

    Now if you can't easily restart these killed processes, etc. Then I would suspect that you should rename the file that is open to some other name. Copy in the new file. Then re-boot. Once a file is open, the name doesn't matter. The running processes continue to use the old file until re-boot or restart.

    If this is a daemon (service in Windoze), then you can potentially restart the service..if it is "well-behaved", it will re-init with the new file and drop the old file. The old file is "deleted" with all processes using it have closed that file. Once a file is open, something like a file id, or node id is used, not the name. You can change the name without affecting any processes currently using the file.

      Thank you all for your replies. I will follow up on them this week! Tim