On Jul 8, 12:45 pm, Tim Golden <m...@timgolden.me.uk> wrote: > Rajat wrote: > > On Jul 8, 4:57 am, Lawrence D'Oliveiro <l...@geek- > > central.gen.new_zealand> wrote: > >> In message <mailman.2795.1246997268.8015.python-l...@python.org>, Christian > > >> Heimes wrote: > >>> By the way most operating systems don't lock a file when it's opened for > >>> reading or writing or even executed. > >> The general conclusion seems to be that mandatory locking is more trouble > >> than it's worth. > > > My OS is a windows XP sp3. All I'm trying to achieve is to close an > > application ( which could be a notepad, a wordpad or some other text > > editor) that have opened my file. Once the file is closed I can easily > > delete that file. > > > I guess, if file is opened by one of that application, the file must > > be locked and so is the reason I cannot delete the file. > > I assume that your real requirement is: I can't open/close/delete > this file; it must be locked by something else; what is that > something else? > > The simplest thing is probably to run sysinternals' handle util: > > http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx > > and use the subprocess module to parse the output. > That will give you the pid, and you can then use, eg, psutil: > > http://code.google.com/p/psutil/ > > to get the details of the process. > > TJG- Hide quoted text - > > - Show quoted text -
I've used the Handle.exe and got the following results: ------------------------------------------------------------------------------ notepad.exe pid: 3540 COMP\rajatd C: File (RW-) C:\Documents and Settings\rajatd\Desktop 10: File (RW-) C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common- Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83 44: File (RW-) C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common- Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83 7C: Section \BaseNamedObjects\ShimSharedMemory ------------------------------------------------------------------------------ wordpad.exe pid: 2212 COMP\rajatd 1C: File (RW-) C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common- Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83 40: File (RW-) C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common- Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83 74: Section \BaseNamedObjects\ShimSharedMemory F8: Section \BaseNamedObjects \CiceroSharedMemDefaultS-1-5-21-57989841-1580818891-839522115-1653 170: Section \BaseNamedObjects\RotHintTable 184: File (RW-) C:\Documents and Settings\rajatd\My Documents I've also parsed this output for the PIDS. But no where in the result I got to know what file has been associated with a PID. Does for this I need to use pustil? -- http://mail.python.org/mailman/listinfo/python-list