I have an autoit script that I run several times through the day to back up my user's documents to a secure server. Recently, I have found that many of my users have not had important documents backed-up as they have left the file open in word/pdf etc...
I have researched and Windows Restart Manager seemed to be a way around this problem but shutting down the process without restarting the computer or interrupting the user's workflow.
I have searched for code examples in how to implement this but can only find this one
The code I use so far to tell if the file is in use
Global Const $GENERIC_WRITE = 0x40000000 Global Const $GENERIC_READ = 0x80000000 Global Const $FILE_ATTRIBUTE_NORMAL = 0x00000080 Global Const $OPEN_EXISTING = 3 Func _fileinuse($file) $hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $file, "int", BitOR($GENERIC_READ, $GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_ATTRIBUTE_NORMAL, "int", 0) If $hFile = -1 Then Return("yes") Else DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return("no") EndIf EndFunc
This is how I call it in the main script:
If _fileinuse($file) = "no" Then _BackUp($file)
If anyone has any idea where I can find documentation on autoit implementation or code examples I would be grateful
User contributions licensed under CC BY-SA 3.0