Jump to content

Need Help (Learning to code in autoit)


R33F
 Share

Recommended Posts

Hi all,

I am a newbie in auto it. I have written a code to display information Computer name, logged on user name and time in GUI.Now I want the information to be displayed in notepad and get it saved in Temp directory in c drive.I tried using the Run(Notepad.exe) wherein it opens the notepad.Also used the Send function to get the system information displayed but it is just opening the notepad.

Here is the code where in the system information would open in a Dialog box with text boxes.Now i Need the same information in notepad and save it in the temp directory in c drive.Need Help please.Its driving me crazy!!!!

******************************************************************

#include <GuiConstantsEx.au3>

#include <WindowsConstants.au3>

#include<Date.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()

Local $Input_ComputerName, $Input_CurrentUserName

Local $Input_Date, $Input_Time, $msg

#forceref $Input_ComputerName, $Input_CurrentUserName

GUICreate("Computer Information - By : Para", 350,200, (@DesktopWidth - 350) / 2, (@DesktopHeight - 200) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUICtrlCreateLabel("Computer Name", 10, 10, 150, 20)

GUICtrlCreateLabel("Current User Name", 10, 40, 150, 20)

GUICtrlCreateLabel("Time", 10, 70, 150, 20)

$Input_ComputerName = GUICtrlCreateInput("" & @ComputerName, 180, 10, 280, 20)

$Input_CurrentUserName = GUICtrlCreateInput("" & @UserName, 180, 40, 280, 20)

$input_Time=GUICtrlCreateinput('''' &_Now() , 180, 70, 280, 20 )

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

EndFunc ;

*****************************************************************************

Link to comment
Share on other sites

I see your atleast somewhat famaliar with AutoIt, and I'm sure you've spent a bit of time in the help file, the functions your wanting to look at for storing information will be 1 of the following, decided by preference.

FileWrite()

FileWriteLine()

IniWrite()

IniWrite() is a little more complicated at first, so I suggest FileWriteLine(), you can find all the information you need by looking in the help file, but here is a quick example...

FileWriteLine(@ScriptDir & "\Info.txt","ComputerName: "@ComputerName)
FileWriteLine(@ScriptDir & "\Info.txt","Username: "@Username)
FileWriteLine(@ScriptDir & "\Info.txt","Time: "_Now())

P.S. In order to get your code snips to look all pretty on the forums, use "autoit" & "/autoit" tags, don't forget the brackets though...

[autoit][/autoit]

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Hi,

I did try to use FileWriteLine but only plain text is getting displayed and the information is getting saved in c drive by default which i want.I need the system information as well in notepad.Need Help on this Please....

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include<Date.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    
    Local $Input_ComputerName, $Input_CurrentUserName
    
    
    Local  $Input_Time, $msg

    #forceref $Input_ComputerName, $Input_CurrentUserName
    
    

    FileWriteLine(@ScriptDir & "\Info.txt","ComputerName: @ComputerName")
                       FileWriteLine(@ScriptDir & "\Info.txt","Username: @CurrentUsername")
                     FileWriteLine(@ScriptDir & "\Info.txt","Time: _Now()")

    
EndFuncoÝ÷ Ú«¨µéÚ

P.S. In order to get your code snips to look all pretty on the forums, use "autoit" & "/autoit" tags, don't forget the brackets though...

[autoit][/autoit]

Link to comment
Share on other sites

Hi.

If this is always about the current user on the current machine, this might be what you are looking for:

#include <date.au3>

$MyLogfile="C:\PC-User-Timestamp.log" ; change to e.g. "\\MyServer\Someshare\PC-User-Timestamp.log"

filewriteline($MyLogfile,"Computername=" & @ComputerName & @TAB & "Username=" & @UserName & @TAB & _NowCalcDate() & "@" & _NowTime(5) & @CRLF)
run ("notepad " & $mylogfile)

regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

:o Thanks Rudi IT works...I made it so complicated ..but u did it in 3 simple lines....need to change my logical thinking :D

Hi.

If this is always about the current user on the current machine, this might be what you are looking for:

#include <date.au3>

$MyLogfile="C:\PC-User-Timestamp.log" ; change to e.g. "\\MyServer\Someshare\PC-User-Timestamp.log"

filewriteline($MyLogfile,"Computername=" & @ComputerName & @TAB & "Username=" & @UserName & @TAB & _NowCalcDate() & "@" & _NowTime(5) & @CRLF)
run ("notepad " & $mylogfile)

regards, Rudi.

Link to comment
Share on other sites

:o Thanks Rudi IT works...I made it so complicated ..but u did it in 3 simple lines....need to change my logical thinking :D

Glad to help.

If you hard code the destination file and kick the run("Notepad " ....), then it's just ONE line :D (plus another one for the include statement)

#include <date.au3>
filewriteline("\\Server\Share\my.log","Computername=" & @ComputerName & @TAB & "Username=" & @UserName & @TAB & _NowCalcDate() & "@" & _NowTime(5) & @CRLF)

Take care, that everybody has granted sufficent access rights to the log file. (e.g. NTFS and SHARE rights for a Windooze Server)

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

ini arent that hard to learn..

(these are example of ONE way to do it)

#1 you need the Func

iniwrite ()oÝ÷ Ûl¨ºww*.­Ø«yËh¯&¦¤X¥zv¦y«­¢+Ù%¹¥ÝÉ¥Ñ ÌäíèÀäÈíQMPÀäÈíQMP¹¥¹¤Ìäì¤oÝ÷ Û|¨ºwvØ^±ç-ÚºÚ"µÍ[]Ü]H
    ÌÎNÐÎÌLÕTÕ   ÌLÕTÕ[IÌÎNË   ÌÎNÔÑPÕSÓÌÎNÊoÝ÷ Û¨ºwvØ^(FºÚ"µÍ[]Ü]H
    ÌÎNÐÎÌLÕTÕ   ÌLÕTÕ[IÌÎNË   ÌÎNÔÑPÕSÓÌÎNË  ÌÎNÒÑVIÌÎNÊoÝ÷ Û¨ºwvØ^½©ny«­¢+Ù%¹¥ÝÉ¥Ñ ÌäíèÀäÈíQMPÀäÈíQMP¹¥¹¤Ìäì°ÌäíM
Q%=8Ìäì°Ìäí-dÌäì°Ìäí]¡ÑÙÈå½ÔݹÐѼÝÉ¥ÑѼѡ¥¹¤Ìäì¤oÝ÷ Úz0¸­z)àÇhî²¢éÞyÛhD@¶¢&®¶­sdæ&VBb33´3¢b3#µDU5Bb3#µDU5Bææb33²Âb33µ4T5Dôâb33²Âb33´´Ub33²Âb33²b33²·FRÆ2b33²b33²ÒDTdTÅ@

thats all you need to know about iniwrite() & iniread ()

NOW there are alot more ini functions in the helpfile so have fun :D

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