简体   繁体   English

NSIS文件正在使用中的检查方法

[英]NSIS file in use check methods

Before starting my installation I need to check whether a particular file is in use. 在开始安装之前,我需要检查是否正在使用特定文件。 This is not an executable file, so the option to check for process existence is out of scope. 这不是可执行文件,因此检查进程是否存在的选项超出范围。

My job is to determine whether a database file is currently in use. 我的工作是确定当前是否正在使用数据库文件。 I thought of renaming the file and get the return code. 我想到重命名文件并获取返回代码。 But unfortunately, there is no return code available for the API. 但是很遗憾,该API没有可用的返回码。 Now I'm thinking about calling MoveFile with System plugin. 现在,我正在考虑使用System插件调用MoveFile。 Anyone can suggest anything else ? 有人可以提出其他建议吗?

Edit: 编辑:

FileOpen $0 "$INSTDIR\FILENAME" r
${If} ${Errors}
 MessageBox MB_OK|MB_ICONEXCLAMATION "File in use"
${EndIf}
FileClose $0

I could achive the same by the above method. 我可以通过上述方法达到相同的效果。 If there is other approaches, kindly let me know. 如果还有其他方法,请告诉我。

FileOpen is probably the best way to do this. FileOpen可能是执行此操作的最佳方法。 Renaming is more complicated and probably has more timing issues. 重命名更为复杂,可能还有更多的计时问题。

Use FileOpen with a mode if you want to check if you can write to the file. 如果要检查是否可以写入文件,请在a模式下使用FileOpen。 Not sure if your app always opens the database for exclusive write access or if it has a read-only mode... 不知道您的应用程序是否总是打开数据库以进行独占写访问,或者它是否具有只读模式...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM