views:

265

answers:

4

Is there a way to unlock a file on Windows with a Python script? The file is exclusively locked by another process. I need a solution without killing or interupting the locking process.

I already had a look at portalocker, a portable locking implementation. But this needs a file handle to unlock, which I can not get, as the file is already locked by the locking process.

If there is no way, could someone lead me to the Windows API doc which describes the problem further?

+6  A: 

Bad idea

wefwfwefwe
A: 

Anything you do will affect the other process if that process thinks it has a lock on the file then breaking the lock means that the program has unexpected brhaviour and could brek or corrupt things.

Thus only do this if you know exactly what will happen.

The api used by the other program probably uses msdn LockFile

Mark
A: 

When backup software can't read locked files, I doubt that you can figure out a way using Python.

Aaron Digulla
A: 

If you only need to infrequently read the locked file, you might try to use the Volume Shadow Copy Service

Komat