问题描述
测试应用程序稳定性时,我试图删除/损坏应用程序使用的数据库。操作系统是Windows,文件系统是NTFS,测试语言是C ++。
While testing an application stability I am trying to remove/corrupt database used by the application. OS is Windows, file system is NTFS, tests language is C++.
我需要的是将任何东西粘贴到数据库文件或删除它。但它在运行期间被测试的应用程序锁定。所以也许有人面对这种情况之前,你可以给我/我们一个例子,绕过这个锁的测试代码的可能的方法?
What I need is to paste anything into the database file or remove it. But it is locked by the tested application during the run. So maybe someone faced this case before and you can give me/us an example on possible ways to bypass this lock in test code? Theory or source - I am appreciated for any kind of help.
推荐答案
您必须关闭应用程序的句柄到文件。请记住,您必须在申请中重新打开您的文件。
You'll have to close the handle that your application has to the file. Keep in mind that you'll have to open your file again on your application, I believe.
我发现了一个不同但类似的问题,示例代码解决了您的问题:
I found a different but similar question, with sample code that solves your problem: Force close file by its path on Windows
您只需要复制所有内容,并替换删除文件的部分即可破坏它。我希望它有助于:D
You just need to copy everything and substitute the part that deletes the file for something that corrupts it. I hope it helps :D
这篇关于删除由另一个进程锁定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!