mjbdiver Posted November 30, 2007 Share Posted November 30, 2007 (edited) I've created an AutoIt script that uses a GUI interface for one-click access to programs I use to perform routine maintenance on the computers at the office where I work. Some of these programs are Windows Defender, Norton AntiVirus, Disk Cleanup and so on. The script also creates a log file and adds entries to the log as I run these programs.At the beginning of the script are these variables for creating the log file.$path="\\lrecdops-dc3\d$\home_folders\michael\maintenance\"$file=$path & @ComputerName & ".txt"And here's the segment that runs the NET TIME command. FileOpen ($file, 1)FileWriteLine($file,"Output of NET TIME check:" & @LF)FileClose ($file)RunWait(@ComSpec & " /k " & "net time >>" & $file) When I try running NET TIME from the script I get this error:The process cannot access the file because it is being used by another process.But when I remove the top 3 lines from the NET TIME segment so that only this line is left:RunWait(@ComSpec & " /k " & "net time >>" & $file) The NET TIME command does run and I do see its output in the log file.I think the script is still keeping the log file open even though I have the script close it after writing to it.How do I have my script truly close the log file so I can append the NET TIME output to it? Edited November 30, 2007 by mjbdiver Link to comment Share on other sites More sharing options...
Danny35d Posted November 30, 2007 Share Posted November 30, 2007 (edited) Try this:$FileOpen = FileOpen ($file, 1) FileWriteLine($file,"Output of NET TIME check:" & @LF) FileClose ($FileOpen) RunWait(@ComSpec & " /k " & "net time >>" & $file) You need to close the handle created by FileOpen() function Edit: Welcome to Autoit Edited November 30, 2007 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Developers Jos Posted November 30, 2007 Developers Share Posted November 30, 2007 Try this:$FileOpen = FileOpen ($file, 1) FileWriteLine($file,"Output of NET TIME check:" & @LF) FileClose ($FileOpen) RunWait(@ComSpec & " /k " & "net time >>" & $file) You need to close the handle created by FileOpen() function Edit: Welcome to Autoit.. and use the filehandle on the filewriteline or just forget about the FileOpen and FileClose SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
mjbdiver Posted November 30, 2007 Author Share Posted November 30, 2007 That worked. Thanks for your help! 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