简体   繁体   中英

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. Now I'm thinking about calling MoveFile with System plugin. 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. 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. Not sure if your app always opens the database for exclusive write access or if it has a read-only mode...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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