Jump to content

Best way to output machine name to text file ?


Recommended Posts

Greetings,

I am a "green" AutoIt user. I have created a couple dozen very basic scripts, so my experience is limited. I did a search for what I am looking for, but I wasn't sure I using the correct terms.

I have a script that will test a desktop machine for a specific OS and version, and if true, perform a subroutine. If false, it exits. I have this part working fine. Now what I would like to do is, if true, ALSO have the script write the machine name and username to a text file. Basically, I want to keep track of all users and machines that run the subroutine. So I will need the script to create the file and enter the first username and machine name into it, and then on subsequent runs, have it APPEND the username and machine name to the existing file.

Any help would be much appreciated.

Thanks.

P.

Link to comment
Share on other sites

  • Moderators

@UserName

@ComputerName

@OSVersion

@etc....

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@UserName

@ComputerName

@OSVersion

@etc....

Hi, Thanks for the quick reply, yes I know about those functions, but what I am in need of is the scripting syntax to create the output file, and the syntax to append (redirect) the output of those commands to the file.

Thanks

Link to comment
Share on other sites

  • Moderators

Hi, Thanks for the quick reply, yes I know about those functions, but what I am in need of is the scripting syntax to create the output file, and the syntax to append (redirect) the output of those commands to the file.

Thanks

Well that's going to depend on what exactly you want to do. Most of us aren't mind readers... and those of us that try, waste more of our time guessing at what exactly you need rather than actually being productive.

Why don't you help yourself and create a step by step outline of what exactly you want to occur... then try it... if you fail, then post your steps and the code that failed.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi, Thanks for the quick reply, yes I know about those functions, but what I am in need of is the scripting syntax to create the output file, and the syntax to append (redirect) the output of those commands to the file.

Thanks

Check help file for FileWrite and/or FileWriteLine

My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."

Link to comment
Share on other sites

Don't know if it helps but ind a cmd box you can use pipes to redirect output.

example: in a cmd promt: echo %computername% > c:\name.txt

This will point output to the textfile name.txt (overwrite)

if you want to append to a file ude >>

echo %computername% > c:\name.txt

Like I said, don't know if it helps or if output can be redirected like this in autoit.

Best Regards Mimo

Link to comment
Share on other sites

Well.. if he wants to go using the Run() command it does, but that defeats the purpose, if he was using that he might as well go ahead and do the whole thing in a batch file..

FileWrite() or FileWriteLine()

or, if you really wanted to get creative with the lists

IniWrite()

Link to comment
Share on other sites

Well The tittle says best way to output machine name to text file.

Don't know if it qualifys for best, but it's quick and easy :whistle:

Besides that the knowlage that consol output can be piped to txt files is not that common, so just mentioned it.

Many people use the cmd promt and execute a file, so maybe we should have a crash tut in using cmd?

Best Regards Mimo

Link to comment
Share on other sites

Check help file for FileWrite and/or FileWriteLine

Thanks. FileWriteLine did what I wanted. I had initially started with delcarling varaibles (IE $UN=@username etc) but then I wanted to use the _NOW() function and that got messy (for me anyway). This may be a dumb question, but if I use a function in a script (#INCLUDE <DATE.AU3>), compile it to an EXE do I have to have the actual function file available to any user that runs the script? If so, do I simply copy it from my program files folder to the folder where the script runs from?

What I ended up with for the code is this: I used the commas in the output so that I can easily import the log to other apps.

CODE
;Runs the win2000 procedure.

;This is test line, Insert LIVE DST patch exe here and rem out next line. This would be the actual DST Patch

RunWait(@ComSpec & " /c Dir C:\windows")

;Copies the "label" to the users C drive to determine future need for DST patch

FileCopy("\\Ehinstall\installs\Microsoft\DST 2007 Patches\Windows 2000 DST2007 Hotfix Package - v2\patchdone.txt", "c:\patchdone.txt", 1)

;writes the computername, username, date and time to the log file

$file = FileOpen("\\Ehinstall\installs\DST-Log\dstlog.txt", 1)

FileWriteLine($file, 'MachName, ' & @ComputerName & ', User, ' & @UserName & ', Date Patched, ' & @MON & '/' & @MDAY & '/' & @YEAR & ', ' & @HOUR & ':' & @MIN)

FileClose($file)

MsgBox(0, "Win 2K Success", " Your WIN2K machine was successfully patched for DST ", 10)

Exit

Now my boss wants the log to indicate whether the program (the one that will be in the RunWait line) finishes correctly, or terminates unexpectedly.

Thanks for all the help and suggestions.

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