Does anybody have a script that will check for open files on a machine before maintenance starts? What we are aiming for is a script that will check for open files or programs if it finds open files / programs it will save the files to a folder on the computer and close the program.
What application are you thinking will have the files open? It may not be possible, or require a good bit of integration development to control an already open application. If you're talking about a variety of applications, this becomes even more difficult.
Finding open files should be farily easy.
You may have a shot at finding the logged in user and accessing their security context via the agent.
Trying to make the application(s) save the documents automagically, a very interesting challenge.
If you're ok with just reporting the open files to take manual action, that would be pretty easy and I'm sure I can dig up a script for you, or at least a snippit for you to roll with.
I think your best bet is determining the most common applications that someone might have open and running a procedure that checks to see if they are running (e.g. IF Application is running) and if they are, prompts the user to close them, using an IF user prompt operation. You then have this procedure loop back on itself until all applications are closed.
You can check to see if a user is logged in in the first place, too. If they aren't, forcing the application closed might lose any of their unsaved work, depending on the application. I know most modern office versions will save off temporary backup files periodically that they might be prompted to recover the next time they open the application.
Trying to automatically instruct an application to save the file and close just based on the fact that a particular file is open will be extremely difficult -- I tried searching Google a little bit to see if there was some sort of magic utility to pill this off and didn't come up with anything right away.
Here's a link to the Microsoft document explaining how to use .NET to develop a small program to locate a running copy of a Microsoft Office application and then gain control of it.
If all of your save destinations are consistent and you're only worried about Microsoft Office applications, then your project actually wouldn't be that difficult.
It wouldn't be much of an agent procedure though, just send file and execute. Even if your save destination changed, you could use the logged in user variable to modify the save path by passing it to your executable.
I'm hoping you decide to move forward with this, I'd really like to hear about the results.
I would only want to check Three applications Word, Power Point, Excel.
In Kaseya the first IF Application Running - Tell it what one - Winword.exe.
Then write file ( what does that mean ?) I would assume it means save the word file it just found when it executed the first if statement.
"Then Enter the full path and file name of the destination file." - I would think that would mean where do you want to put it and waht do you want to call it.
When I try it that way the script fail. I know I'm missing a lot. Thanks very much for the help!
rrarnold, what time are you running your maintenance? if there's someone logged in would it be eaiser to just log them out closing all open files? if your maintenance happens at night that may be the way to go. Detecting the app running wouldn't save the work when you close it. If there's someone logged in and working you could do a popup asking them to save and close work.
here's an example on how to close winword.exe, hope this helps get you to where you're trying to go.
<Procedure name="Doc open/close" treePres="3">
<Parameter xsi:type="StringParameter" name="ApplicationName" value="winword.exe"/>
<Statement description="Close the specified application." name="CloseApplication" continueOnFail="false" osType="Windows">
This is possible but is possibly a lot of work depending on how many applications you need to setup. You can use AutoIt to do GUI scripting and mouse actions like file saving. Nice thing is you can compile them into EXEs. So you can use an IF statement to see if winword.exe is running and then run the compiled script (EXE) to save then close. The move onto the next. So on and so forth.