Page 2 of 2 <12
Topic Options
#172584 - 2007-01-09 05:49 PM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, one more...
change:
Code:
IF Open(3, $logfile1, 4 ) = 0
  $x = WriteLine( 3 , $Result1string + Chr(13) + Chr(10) )
ELSE
  BEEP
  ? "failed to open file, error code : [" + @ERROR + "]"
ENDIF


to:
Code:
?
IF Open(3, $logfile1, 4 ) = 0
  $x = WriteLine( 3 , $Result1string + Chr(13) + Chr(10) )
  if @error
   beep
   "Failed to write to the darn file. " @error ?
  else
   "write succeeded." ?
  endif
ELSE
  BEEP
  ? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
sleep 2
_________________________
!

download KiXnet

Top
#172587 - 2007-01-09 06:13 PM Re: HELP! use GetFileTime function to add line to log file [Re: Lonkero]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
If the target file does not exist, the mode should be 5 (4 + 1)?
Open(3, $logfile1, 5 )

Top
#172590 - 2007-01-09 07:04 PM Re: HELP! use GetFileTime function to add line to log file [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
he said he made the file.
thus, there are at least 4 possibilities with his posted code:
- he has no rights to write to the file
- the drive is full
- he is not actually running the posted code
- the code is part of larger file and it exits before it or jumps over the part

but, what the actual reason why the write fails will be shown with the error showing code I modified for him.
_________________________
!

download KiXnet

Top
#172597 - 2007-01-09 08:01 PM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Okay beejay, since you've been attempting to learn how to do it I'll give you an A for effort and I'll provide you with some working code.

As with most scripts it can be accomplished many ways and my example is just one of many.

Code:
;Set options 
If Not @LogonMode
  Break On
Else
  Break Off
EndIf
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')

;Declare our variables
Dim $TimeStamp, $LogFile1, $LogFile2, $Handle, $WL, $OpenFile, $CloseFile
Dim $Result1, $Result2
Dim $Result1string, $Result2string

;Use Split and Join to put the date and time into a variable
$TimeStamp = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),''))

;Place our Logfile locations into variables
$LogFile1 = 'I:\TEST\auditfile1.txt'
$logfile2 = 'I:\TEST\auditfile2.txt'

;Place the files we want to get the file time from into variables
$Result1 = GetFileTime('C:\Program Files\filename1.txt',0)
$Result2 = GetFileTime('C:\Program Files\filename2.txt',0)

;Place the full results into variables including a comma for csv style format
$Result1string = $TIMESTAMP + ',' + @WKSTA + ',' + $Result1
$Result2string = $TIMESTAMP + ',' + @WKSTA + ',' + $Result2

;Use FreeFileHandle to find an available file handle to use
$Handle = FreeFileHandle()
If $Handle > 0
  $OpenFile = Open($Handle,$LogFile1,5)
  If @ERROR
    'Error opening LogFile1: ' + @ERROR + ' - ' + @SERROR ?
  Else
    $WL = WriteLine($Handle, $Result1string)
    If @ERROR
      'Error updating LogFile1: ' + @ERROR + ' - ' + @SERROR ?
    EndIf
  EndIf
  $CloseFile = Close($Handle)
EndIf
;We close the file and move on to the next file
;If we did not close the file we could not use the same variable for the Handle

$Handle = FreeFileHandle()
If $Handle > 0
  $OpenFile = Open($Handle,$LogFile2,5)
  If @ERROR
    'Error opening LogFile2: ' + @ERROR + ' - ' + @SERROR ?
  Else
    $WL = WriteLine($Handle, $Result1string)
    If @ERROR
      'Error updating LogFile2: ' + @ERROR + ' - ' + @SERROR ?
    EndIf
  EndIf
  $CloseFile = Close($Handle)
EndIf



.

Top
#172615 - 2007-01-10 09:16 AM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
beejay Offline
Fresh Scripter

Registered: 2007-01-04
Posts: 12
Here's my revised code - but It's still not doing the trick. - it's not beeping either
Code:
 ; * Create the TIMESTAMP 
; a TIMESTAMP is not strictly necessary!

IF @MONTHNO < 10 
$MONTH= "0" + "@MONTHNO"
ELSE
$MONTH= "@MONTHNO"
ENDIF

IF @MDAYNO < 10 
$DAY= "0" + "@MDAYNO"
ELSE
$DAY= "@MDAYNO"
ENDIF

$timestamp = "@YEAR" + "-" + "$MONTH" + "-" + "$DAY" + " " + @TIME
$ComputerName   = @WKSTA

$logfile1 = "I:\foldername\auditfile1.txt"
$logfile2 = "I:\foldername\auditfile2.txt"

$Result1 = GetFileTime("C:\Program Files\filename1.txt", 0)
$Result2 = GetFileTime("C:\Program Files\filename2.txt", 0)

$Result1string = "$TIMESTAMP;$ComputerName;$Result1"
$Result2string = "$TIMESTAMP;$ComputerName;$Result2"        

? IF Open(3, $logfile1, 4 ) = 0
  $x = WriteLine( 3 , $Result1string + Chr(13) + Chr(10) )
  if @error
   beep
   "Failed to write to the darn file. " @error ?
  else
   "write succeeded." ?
  endif
ELSE
  BEEP
  ? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
sleep 2

If Close(3)
  Beep
  ? "Error closing file!"
EndIf

? IF Open(3, $logfile2, 4 ) = 0
  $x = WriteLine( 3 , $Result2string + Chr(13) + Chr(10) )
  if @error
   beep
   "Failed to write to the darn file. " @error ?
  else
   "write succeeded." ?
  endif
ELSE
  BEEP
  ? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
sleep 2

exit

Top
#172619 - 2007-01-10 10:58 AM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well sorry but I gave you working code already.

I don't have time to keep debugging your old code tonight. Please adapt the code I provided you or wait for one of the other guys to assist you as it's time for me to hit the sack.

.

Top
#172620 - 2007-01-10 11:37 AM Re: HELP! use GetFileTime function to add line to log file [Re: NTDOC]
beejay Offline
Fresh Scripter

Registered: 2007-01-04
Posts: 12
NTDOC:

OK - Thanks & goodnight - I'll try adapting it & let you / colleagues know if I manage to overcome this little b******

Cheers

Top
#172623 - 2007-01-10 02:31 PM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
beejay Offline
Fresh Scripter

Registered: 2007-01-04
Posts: 12
Hi all

I've tried a few tweaks and to simplify the code - the latest effort is below, but I still can't get the little b***** to play ball & do the job.

getting very frustrated with this one

Thanks from one kixtart novice


Code:
; * Create the TIMESTAMP 
; a TIMESTAMP is not strictly necessary!

IF @MONTHNO < 10 
$MONTH= "0" + "@MONTHNO"
ELSE
$MONTH= "@MONTHNO"
ENDIF

IF @MDAYNO < 10 
$DAY= "0" + "@MDAYNO"
ELSE
$DAY= "@MDAYNO"
ENDIF

$timestamp = "@YEAR" + "-" + "$MONTH" + "-" + "$DAY" + " " + @TIME
$ComputerName   = @WKSTA

$logfile1 = "I:\foldername\auditfile1.txt"
$logfile2 = "I:\foldername\auditfile2.txt"

$Result1 = GetFileTime("C:\Program Files\filename1.txt", 0)
$Result2 = GetFileTime("C:\Program Files\filename2.txt", 0)   

IF Open( 3 , "I:\foldername\auditfile1.txt" , 5 ) = 0
  $x = WriteLine( 3 , $TIMESTAMP;$ComputerName;$Result1 + Chr(13) + Chr(10) )
ELSE
  BEEP
  ? "failed to open file, error code : [" + @ERROR + "]"
ENDIF

If Close(3)
  Beep
  ? "Error closing file!"
EndIf

IF Open( 3 , "I:\foldername\auditfile2.txt" , 5 ) = 0
  $x = WriteLine( 3 , $TIMESTAMP;$ComputerName;$Result2 + Chr(13) + Chr(10) )
ELSE
  BEEP
  ? "failed to open file, error code : [" + @ERROR + "]"
ENDIF

If Close(3)
  Beep
  ? "Error closing file!"
EndIf


exit 

Top
#172627 - 2007-01-10 04:13 PM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
beejay Offline
Fresh Scripter

Registered: 2007-01-04
Posts: 12
NTDOC:

I've used your script that you did last night - thanks for spending time on it; on logging on, however, the screen displays an error message for a fraction of a second:

000Script error : expected expression !.
$SO=SetOption('Explicit','On')

it doesn't add any data to the log files as requested.

Does this error mean anything to you? (sorry but I don't know)

As ever, entirely grateful.

Top
#172631 - 2007-01-10 05:50 PM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes, you have old kixtart version.

however, your old code should have worked and if it didn't beep, you should check again that it actually ran at all.
the code was written in such a manner that it always outputs something and sleeps a bit.
so if you can't get anything to the console with it, you are not actually running it.

anyway, you could start by upgrading your kixtart to at least 4.22
_________________________
!

download KiXnet

Top
#172634 - 2007-01-10 07:11 PM Re: HELP! use GetFileTime function to add line to log file [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Quote:
you could start by upgrading your kixtart to at least 4.22


And if you're going to upgrade to 4.22 then you might as well upgrade to the latest release version 4.53

As Jooel was saying though even a very old KiXtart 3.63 should give output with the code he was helping you with. The code I gave you is a bit newer and requires the 4.x version of KiXtart. You should also be running/testing this as a stand-alone script and not as part of your main or logon script until you get it working.

.

Top
#172683 - 2007-01-11 11:44 AM Re: HELP! use GetFileTime function to add line to log file [Re: NTDOC]
beejay Offline
Fresh Scripter

Registered: 2007-01-04
Posts: 12
I've updated to 4.53 version replacing ALL 6 kixtart files (before I had only replaced kix32.exe (windows 2003 server) as in the guidance - and EUREKA!!!.

Before I sign off (until next time) a big THANK YOU to all involved, for your patience and help, especially NTDOC for writing the script now in use.

Au revoir

Beejay

Top
#172698 - 2007-01-11 07:41 PM Re: HELP! use GetFileTime function to add line to log file [Re: beejay]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
6 files? Unless you have WIntendos, you need only the KiX32.exe and WKiX32.exe files.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.075 seconds in which 0.033 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org