Sign in to follow this  
Followers 0
mjbdiver

Script keeping log file open

4 posts in this topic

#1 ·  Posted (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 by mjbdiver

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

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 :P

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

That worked. Thanks for your help!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0