Jump to content

Windows Vista produces Invalid File Handle Error


Recommended Posts

I have a script that does some logging. It has worked with Windows XP, but now we're doing some testing with Windows Vista and are getting "Invalid file handle used" errors on the first FileWriteLine.

$filePClog = FileOpen(@logonserver & "\logs$\PC\" & @computername & ".log", 1)
$fileUSERlog = FileOpen(@logonserver & "\logs$\USER\" & @UserName &".log",1)

FileWriteLine($filePClog, "Log On  :: " & @MON&"/"&@MDAY&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC & " :: " & @UserName)
FileWriteLine($fileUSERlog, "Log On  :: " & @MON&"/"&@MDAY&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC & " :: " & @ComputerName)

FileClose($filePClog)
FileClose($fileUSERlog)

This script is called by another script (which does a RunAsSet so we can write to the log files...regular users don't have permissions to them), which is called from the logon script. Any ideas?

Thanks,

Matt

Link to comment
Share on other sites

You have no error handling in the event the file cannot be opened.

$filePClog = FileOpen(@logonserver & "\logs$\PC\" & @computername & ".log", 1)
If $filePClog = -1 Then
    MsgBox(0, "Error", "Unable to open:"&@CRLF&@logonserver & "\logs$\PC\" & @computername & ".log")
    Exit
EndIf
$fileUSERlog = FileOpen(@logonserver & "\logs$\USER\" & @UserName &".log",1)
If $fileUSERlog = -1 Then
    MsgBox(0, "Error", "Unable to open:"&@CRLF&@logonserver & "\logs$\USER\" & @UserName &".log")
    Exit
EndIf

FileWriteLine($filePClog, "Log On  :: " & @MON&"/"&@MDAY&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC & " :: " & @UserName)
FileWriteLine($fileUSERlog, "Log On  :: " & @MON&"/"&@MDAY&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC & " :: " & @ComputerName)

FileClose($filePClog)
FileClose($fileUSERlog)

Try that and see if you get an error message dialog box.

EDIT:

You also have a "$" character after "logs" in the filename. I am not sure if this is intentional or if it is a typo. $ characters are valid in folder and filenames, but it just doesn't look in place.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...