Kaseya Community

Script in VBS to write the time to a log file

  • Hi all, I'm trying to create a VBS script to write the time to a log file. I will then have Kaseya read the time and determine a course of action based on the time.

    Problem is, I think I need this to be as a string to work correctly. I first need to execute the VBS script, which I think might look something like this:

    Dim currentTime As Date
    currentTime = TimeOfDay

    set oFSO=CreateObject("Scripting.FileSystemObject")
    set objTextFile = oFSO.OpenTextFile("Timelog.txt",8,True)
    objTextFile.WriteLine ("Current time is") & currentTime
    objTextFile.Close
    set objTextFile = Nothing
    set oFSO = Nothing

    However that fails.
    Assuming the above was working, I would have Kaseya check the file content, make that a variable, and then use the to determine an action.

    Can anyone tell me what's wrong with my above script?

    Thanks!
    Jason

    Legacy Forum Name: Script in VBS to write the time to a log file,
    Legacy Posted By Username: jasonrdavis
  • echo %time% > time.txt

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: SMason
  • I didn't go through the code 100%, so I'm not sure if your write to file works properly but...


    objTextFile.WriteLine ("Current time is") & currentTime



    objTextFile.WriteLine ("Current time is ") & Time


    you can ditch

    Dim currentTime As Date
    currentTime = TimeOfDay


    Note: you'll want to tidy my code up a lot.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: thirteentwenty
  • SMason
    echo %time% > time.txt


    Love it! Wink

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: lowray1975