AutoitMike Posted March 16, 2022 Posted March 16, 2022 A process of mine opens a HML file, modifies it and then saves, closes it. I then need to run an.exe that opens this file right after this.. However, nothing that I find on this forum works that supposedly tests to see if the fie is still open, ready to be used by another process. Right now, I just Sleep(2000) . I would like something cleaner than this. This function, for example, returns False when nothing has it opened or if I open the file with notepad or any other editor. I am running on a win7 laptop, if that has any bearing. $File="C:\Utilities\test\report.hr5" MsgBox(0,"", _FileInUse($File)) Exit Func _FileInUse($sFilePath) ; By Nessie. Modified by guinness. Local Const $hFileOpen = _WinAPI_CreateFile($sFilePath, $CREATE_ALWAYS, $FILE_SHARE_WRITE) If $hFileOpen Then _WinAPI_CloseHandle($hFileOpen) Return False EndIf Local $fReturn = False If _WinAPI_GetLastError() = 32 Then $fReturn = True Return $fReturn EndFunc
Nine Posted March 16, 2022 Posted March 16, 2022 25 minutes ago, AutoitMike said: A process of mine Can you modify it to send a IPC signal ? How often does this process open/modify/close the file ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AutoitMike Posted March 16, 2022 Author Posted March 16, 2022 I dont know what IPC signal is. My process only runs one time.
Earthshine Posted March 16, 2022 Posted March 16, 2022 you can scan for that process that modifies it, then when it's gone, do your thing My resources are limited. You must ask the right questions
Nine Posted March 16, 2022 Posted March 16, 2022 Forget the IPC signal, more importantly can you modify it ? Is @Earthshine proposal good enough (seems to me a good approach) ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ad777 Posted March 16, 2022 Posted March 16, 2022 (edited) 6 hours ago, AutoitMike said: I then need to run an.exe that opens this file right after this.. However, nothing that I find on this forum works that supposedly tests to see if the fie is still open, ready to be used by another process. Note:i use FileDelete to Detect if the file open. i have this script but it work for exe/dll: #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> $File = "D:\Main.exe" _CHKFileInUse($File) Func _CHKFileInUse($File) Local $ST For $i = 1 To StringLen($File) $ST = StringRight($File, $i) if StringInStr($ST, "\") Then ExitLoop EndIf Next FileCopy($File, @TempDir & "\" & StringReplace($ST, "\", ""), $FC_OVERWRITE + $FC_CREATEPATH) if FileDelete($File) = 0 Then Return MsgBox(64, "", "File In Use") Else Return MsgBox(64, "", "File Not In Use") FileCopy(@TempDir & "\" & StringReplace($ST, "\", ""), $File) EndIf EndFunc ;==>_CHKFileInUse Edited March 16, 2022 by ad777 none
AutoitMike Posted March 16, 2022 Author Posted March 16, 2022 (edited) My installation does not have WinAPIFiles.au3, but I do have WinAPI.au3 I dont have WinAIObj.au3 My version has the extensive MS Word interface and functionality for which I am fully taking advantage of. Edited March 17, 2022 by AutoitMike
Earthshine Posted March 16, 2022 Posted March 16, 2022 Be easier to loop while looking for your process name. If that program above crashes in the middle of it you could lose your file. It’s a horrible idea to be deleting a file to tell if it’s not in use My resources are limited. You must ask the right questions
AutoitMike Posted March 17, 2022 Author Posted March 17, 2022 (edited) I am not sure what the process name is. I am using the following code to open the file in question: Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load($ReportFile) ;just some of the code here: ;add node year built and update it $oOther = $oXML.SelectSingleNode('//template/genInfo/GA/SM[1]') $Node=$oXML.CreateElement('SMT') $oOther.AppendChild($Node) $oOther = $oXML.SelectSingleNode('//template/genInfo/GA/SM[1]/SMT') $oOther.text=$YearBuilt $oxml.save($ReportFile) ;Now, I got to run an exe that starts up and opens this file. But what is the name of the process that would have $ReportFile open? Edited March 17, 2022 by AutoitMike dont want to reveal actual file data
Earthshine Posted March 17, 2022 Posted March 17, 2022 The process name is the name of the exe you run that modifies the file. You can have a while loop that scans for it’s existence My resources are limited. You must ask the right questions
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now