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

I need to be able to move a directory that is being used by another process, and, hence, locked.

I can write a Perl wrapper around TASKLIST.EXE and OH.EXE to find the process that has an open handle on the directory, and then kill the process. However, I am wondering if it is possible to find the open handles of each process using only Perl. Thanks.

C:\scratch2>oh -p 152 00000098 cmd.exe KeyedEvent 0004 \KernelObjects\CritSecOutO +fMemoryEvent 00000098 cmd.exe Directory 0008 \KnownDlls 00000098 cmd.exe File 000c \scratch2\freddy.old 00000098 cmd.exe Directory 0014 \Windows 00000098 cmd.exe WindowStation 0024 \Windows\WindowStations\Wi +nSta0 00000098 cmd.exe Directory 0028 \BaseNamedObjects 00000098 cmd.exe WindowStation 002c \Windows\WindowStations\Wi +nSta0 00000098 cmd.exe Desktop 0030 \Default 00000098 cmd.exe Key 0034 \REGISTRY\MACHINE 00000098 cmd.exe Key 0044 \REGISTRY\MACHINE\SOFTWARE +\Microsoft\Windows NT\CurrentVersion\Drivers32 00000098 cmd.exe Key 0054 \REGISTRY\MACHINE\SOFTWARE +\Microsoft\Windows NT\CurrentVersion\Drivers32 00000098 cmd.exe Semaphore 0058 \BaseNamedObjects\shell.{A +48F1A32-A340-11D1-BC6B-00A0C90312E1} 00000098 cmd.exe Key 005c \REGISTRY\USER\S-1-5-21-32 +9068152-838170752-1801674531-8171 00000098 cmd.exe File 0060 \WINDOWS\WinSxS\x86_Micros +oft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1 +ff9 00000098 cmd.exe Event 0064 \BaseNamedObjects\userenv: + User Profile setup event 00000098 cmd.exe Key 0068 \REGISTRY\MACHINE\SYSTEM\C +ontrolSet001\Control\Nls\Locale 00000098 cmd.exe Key 006c \REGISTRY\MACHINE\SYSTEM\C +ontrolSet001\Control\Nls\Locale\Alternate Sorts 00000098 cmd.exe Key 0070 \REGISTRY\MACHINE\SYSTEM\C +ontrolSet001\Control\Nls\Language Groups


Replies are listed 'Best First'.
Re: Replicating TASKLIST.EXE and OH.EXE functionality in Perl
by PodMaster (Abbot) on Jan 05, 2006 at 05:23 UTC
    However, I am wondering if it is possible to find the open handles of each process using only Perl.
    Its possible. You simply grab a few modules, and then reimplement what tasklist.exe oh.exe do. At the very least you should use Win32::Process::Info and Win32::API (while reading msdn).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.