Husker_Jason Posted June 23, 2023 Share Posted June 23, 2023 (edited) I have a stand alone Close Program function that I call when I want to close the program so I don't have to keep adding it to each program. I call it from any other program that I write where I could be doing anything. The function does some simple error checking and provides a reason why the program is closing or asks the user are you sure you want to close the program. In some instances, I may have one or more files open that I were opened using the FileOpen function when this function is called. I know it is best practice to close any open files with the FileClose function prior to exiting the program. What is the best way to pass any open file handles I might have created to that function so I can properly close them? Is there a way to list any open file handles that the AutoIt program has created? I thought about writing a simple file handler routine that stores all files and handles in a global variable so that it can be accessed at any time from any subroutine, but thought there might be a better way. Any thoughts would be appreciated. Edited June 23, 2023 by Husker_Jason Link to comment Share on other sites More sharing options...
Andreik Posted June 23, 2023 Share Posted June 23, 2023 You might use NtQuerySystemInformation() to get an array of all handles and then filter for your process but it might be a challenge to get the file name associated with a handle. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Husker_Jason Posted June 28, 2023 Author Share Posted June 28, 2023 Yea, I was looking for an easy way to keep track of them. In the end I ended up just writing a function that goes between the FileOpen and FileClose commands that writes each new file I open to an array with the handle and file path and then removes those values from the storage array when I close them. If there are any files still open when I close the program, it goes through and cleans them up. Probably overkill as I know AutoIt automatically closes open files when it closes, but I like to keep things neat. Link to comment Share on other sites More sharing options...
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