Non-intrusively unlock file on Windows

删除回忆录丶 提交于 2019-12-22 17:55:28

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1544275/non-intrusively-unlock-file-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!