Sign in to follow this  
Followers 0
gkrapp

How To... Filewrite With Macros/varables?

3 posts in this topic

dear all,

this is my first script i'm trying to write with autoit_v3.

it's a kind of logon script which will also add a line to an log-file.

here's a part of my sample code, but i still don't know how to write

an variable as text to the file.

$logfile = FileOpen ("\\server\logfiles$\login.log" , 1)

FileWriteLine ($logfile, '@username logged on to @computername at @MDAY.@MON.@YEAR on @HOUR:@MIN' )

FileClose ($logfile)

actually inside the logfile only "@username" and all this stuff is written.

any help would be appreciated! thank a lot in advance

greetz

gerhard

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

very close, just need variables and @macros to be outside of strings:

$logfile = FileOpen ("\\server\logfiles$\login.log" , 1)
FileWriteLine ($logfile, @username & ' logged on to ' & @computername&' at '& @MDAY & '.' & @MON & '.' & @YEAR & ' on ' & @HOUR & ':' &@MIN)
FileClose ($logfile)

usage is @clrf & $var & 'I am a string'

not '@crlf $var I am a string'

...edit and if you are just appending a line to a file, you can skip the file open and close, it will do it automatically if a filename is given.

FileWriteLine ("\\server\logfiles$\login.log", @username & ' logged on to ' & @computername&' at '& @MDAY & '.' & @MON & '.' & @YEAR & ' on ' & @HOUR & ':' &@MIN)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

hey,

it works very well! :D

thanks for your support and also for your tip!

gerhard

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