Jump to content

How To... Filewrite With Macros/varables?


Recommended Posts

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

Link to comment
Share on other sites

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.

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...