Jump to content

How to Store data


Recommended Posts

hi! i'm new here and i have one questions. Can i store data from script?

ex:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    case $Buttoncancel
        Exit
    case $ButtonOk
        $Id = GUICtrlRead($input1)
        $Pw = GUICtrlRead($passwordedit)
        MsgBox(0,"","Register Succesfull")
        ExitLoop
    EndSwitch
WEnd

Can i store data from $id and $pw and use other times?

Sry for my bad english :unsure:

Link to comment
Share on other sites

I'm guessing you mean store the data, close the script. Run the script another day and use the saved data?

There are many ways to do this my favorite is the ini functions (IniRead IniWrite)

Also FileRead and FileWrite. And if you really wanted to, you could even store the data in the regestry with RegRead and RegWrite.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

my script look like this

#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3>  #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Password Dialog", 396, 228, -1, -1) GUISetIcon("D:\008.ico") $Input1 = GUICtrlCreateInput("", 38, 88, 233, 21) $PasswordEdit = GUICtrlCreateInput("", 38, 144, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $ButtonOk = GUICtrlCreateButton("Register", 294, 72, 75, 57, 0) $ButtonCancel = GUICtrlCreateButton("Cancel", 295, 136, 75, 33, 0) $EnterPassLabel = GUICtrlCreateLabel("PW", 38, 124, 77, 17) $Label1 = GUICtrlCreateLabel("ID", 38, 65, 77, 17) $Register = GUICtrlCreateLabel("Register", 160, 8, 106, 36) GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Pic1 = GUICtrlCreatePic("D:\ice_dragons.jpg", 8, 8, 380, 212, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ###  While 1   $nMsg = GUIGetMsg()     Switch $nMsg    Case $GUI_EVENT_CLOSE       Exit    case $Buttoncancel      Exit    case $ButtonOk      $Id = GUICtrlRead($input1)      $Pw = GUICtrlRead($passwordedit)        MsgBox(0,"","Register Succesfull")      ExitLoop    EndSwitch WEnd  #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Password Dialog", 396, 228, -1, -1) GUISetIcon("D:\008.ico") $Input1 = GUICtrlCreateInput("", 38, 88, 233, 21) $PasswordEdit = GUICtrlCreateInput("", 38, 144, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $ButtonOk = GUICtrlCreateButton("Login", 294, 72, 75, 57, 0) $ButtonCancel = GUICtrlCreateButton("Register", 295, 136, 75, 33, 0) $EnterPassLabel = GUICtrlCreateLabel("Pw", 38, 124, 19, 17) $Label1 = GUICtrlCreateLabel("Id", 38, 65, 13, 17) $Register = GUICtrlCreateLabel("Register", 160, 8, 106, 36) GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Pic1 = GUICtrlCreatePic("D:\ice_dragons.jpg", 8, 8, 380, 212, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ###  While 1  $nMsg = GUIGetMsg()     Switch $nMsg        Case $GUI_EVENT_CLOSE           Exit        case $buttonok          $Id1 = GUICtrlRead($input1)             $Pw1 = GUICtrlRead($passwordedit)           if $pw1 = $pw and $Id1 = $id Then               msgbox(0,"","Login Seccesfull" & @crlf &"Have Fun!")                exit            Else                msgbox(0,"","Invalid Id or Pw" & @crlf & "Please try again!")           EndIf   EndSwitch WEnd
and i want store data $id and $pw and then use them to login without write again in first gui :unsure:

Sry for my bad english :>

Edited by pl4y0n
Link to comment
Share on other sites

You will have to write a condition at the start of your script to look for whatever method you choose to store data.

If FileExists(filename.ini) Then

read the data from the file

Else

Create the file and save the data to it

EndIf

(Semi-Psudo code)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Hi pl4y0n,

Using AutoIt you can store data in a variety of ways, from simple text files,Ini files and logs to powerful database management systems like Oracle, MySQL and SQLite. A wealth of information/examples on how to employ these methods are available if you search the help-file, the AutoIt Wiki and the forums.

A screen clip of one of the available indispensable references

Posted Image

Here are a couple of quick excerpts.

1. Writing to a simple text file (from the help-file)

$file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, "Line1")
FileWrite($file, "Still Line1" & @CRLF)
FileWrite($file, "Line2")

FileClose($file)

2. Writing to an Ini file (also from the help-file)

IniWrite("C:\Temp\myfile.ini", "section2", "key", "this is a new value")

Hope this helps. :unsure:

-smartee

EDIT: Re-uploaded screen clip.

Edited by smartee
Link to comment
Share on other sites

I copy and paste these functions into almost every script I make.

It makes managing your data very simple.

#include<Crypt.au3>
#include<SQLite.au3>
#include<SQLite.dll.au3>
Global $DB ,$NoUpdate = False;This means that pre-existing data is not to be updated.
Global $DataTable = "ScriptData";this is your "$Table"

Func _StartUp()
    _Crypt_Startup()
    _SQLite_Startup()
    If @error Then
        MsgBox(16, "ERROR", "SQLITE ERROR!!!")
        Return SetError(0, 0, "")
    EndIf
    OnAutoItExitRegister("_My_Janitor")
    If Not FileExists("Memory.db") Then
        $DB = _SQLite_Open("Memory.db")
        _SQLite_Exec($DB, "CREATE TABLE "&$DataTable&" (Adress,Val1,Val2,Val3,Val4,Val5);");You can create more tables of different names depending on your needs.
        Return SetError(0, 1, 1)
    Else
        $DB = _SQLite_Open("Memory.db")
    EndIf
    Return SetError(0, 0, 1)
EndFunc   ;==>_StartUp


Func _DataCheck($Table)
    Local $hQuery, $aRow, $i = 0
    _SQLite_Query(-1, "SELECT * FROM "&$Table&";", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $i += 1
        MsgBox(0, "Item" & $i, $aRow[0], 3)
    WEnd
    Return 1
EndFunc   ;==>_DataCheck

Func _SetDataEx($Data, $Table, $Adress, $UKEY = 0x0006548)
    Local $Key, $CData
    _Crypt_Startup()
    $Key = _Crypt_DeriveKey($UKEY, $CALG_RC4)
    $CData = _Crypt_EncryptData($Data, $Key, $CALG_USERKEY)
    _DataAddEx($Table, $Adress, $CData)
    If @error Then Return @error
    _Crypt_DestroyKey($Key)
    _Crypt_Shutdown()
    Return 1
EndFunc   ;==>_SetDataEx

Func _GetDataEx($Table, $Adress, $UKEY = 0x0006548)
    Local $RData, $Key, $Data, $CData
    _Crypt_Startup()
    $Key = _Crypt_DeriveKey($UKEY, $CALG_RC4)
    $RData = _DataQueryEx($Table, $Adress)
    $CDta = _Crypt_DecryptData($RData, $Key, $CALG_USERKEY)
    If @error Then Return 0
    Local $Data = BinaryToString($CDta)
    If $Data = "" Then Return 0
    _Crypt_DestroyKey($Key)
    _Crypt_Shutdown()
    Return $Data
EndFunc   ;==>_GetDataEx

Func _DataAddEx($Table, $Adress, $Val1, $Val2 = "", $Val3 = "", $Val4 = "", $Val5 = "")
    Local $Data
    _SQLite_QuerySingleRow($DB, "SELECT Adress FROM " & $Table & " WHERE Adress='" & $Adress & "'", $Data)
    If $Data[0] <> "" Then; If there is an error here than its your fault... the data base doesn't exist
        ;If Not MsgBox(17, "Data exists", "Information for this file exists." & @CRLF & @CRLF & "Continue Operation?") = 1 Then Return 1
        If $NoUpdate Then Return 1
        _SQLite_Exec($DB, "UPDATE " & $Table & " SET Val1='" & $Val1 & "', Val2='" & $Val2 & "', Val3='" & $Val3 & "', Val4='" & $Val4 & "', Val5='" & $Val5 & "' WHERE Adress='" & $Adress & "'")
    Else
        _SQLite_Exec($DB, "INSERT INTO " & $Table & " (Adress,Val1,Val2,Val3,Val4,Val5) VALUES ('" & $Adress & "','" & $Val1 & "','" & $Val2 & "','" & $Val3 & "','" & $Val4 & "','" & $Val5 & "');")
    EndIf
    Return 1
EndFunc   ;==>_DataAddEx

Func _DataQueryEx($Table, $Adress, $Ar = False)
    Local $Ret
    If _SQLite_QuerySingleRow($DB, "SELECT * FROM " & $Table & " WHERE Adress='" & $Adress & "'", $Ret) == $SQLITE_OK Then ; =>"*"<= means all...
        If $Ret[0] == "" Then
            Return 0
        Else
            If $Ar Then Return $Ret
            If $Ret[1] = "" Or $Ret[1] = ' ' Then Return 0
            Return $Ret[1]
        EndIf
    EndIf
    Return 0
EndFunc   ;==>_DataQueryEx

Func _DataDel($Table, $Adress)
    Local $Ret
    _SQLite_QuerySingleRow($DB, "SELECT Adress FROM " & $Table & " WHERE Adress='" & $Adress & "'", $Ret)
    If $Ret[0] <> "" Then
        _SQLite_Exec($DB, "DELETE FROM " & $Table & " WHERE Adress='" & $Adress & "'")
    EndIf
EndFunc   ;==>_DataDel

Func _My_Janitor()
    _Crypt_Shutdown()
    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc   ;==>_My_Janitor
Edited by System238
Link to comment
Share on other sites

Thx you smartee now i understood the create writing and ect. :unsure:

System238 your scrip is so hard for me i'm just a newbie.

Anyways thx you guys!

Sry for my bad english :>

sry for double post but i cant edit my old post dk why

i have one more question. Can i create a script for register and save data to a notepad and then create an other to login using that notepad data?

but now with same name ex : $pw1 = 123 $id1 = 123 ; $id2 = 234 $pw2 = 234

Edited by pl4y0n
Link to comment
Share on other sites

sry for double post but i cant edit my old post dk why

i have one more question. Can i create a script for register and save data to a notepad and then create an other to login using that notepad data?

I'm going to assume that English isn't your first language, it ain't mine either.

First of all, "NotePad.exe" is an executable program/application that was designed to edit basic text files.

I will also make the assumption that when you typed "create a script for register and save data to a notepad" you actually meant to type "How should I go about writing a script that will launch notepad and enter some text into it and save it to a text file."

and I will also assume that "then create an other to login using that notepad data"" actually means "and how can I restart the process after a user logs on?".

If I am correct, the first step you should take in your quest to improve your familiarity with the syntax used by AutoIt3.exe is to open the "Scite" text editor that comes with "AutoIt" and look for the "help" button in the tool bar and lick it. (I noticed the typo :\)

Some more buttons will appear, another button named "help" will be visible.

click on the help button again and a new window will appear, there will be a tab view area and one of those tabs will display the name "content", click on that button and go to the tree view area.

there will be an entry titled "Tutorials", in that area is your answer.

TL;DR

Use the help file..

Edit: Wrote a quick tutorial for ya cause i know it does look pretty hard, it looked hard to me when I first found out about SQLite support in autoit 3 days ago.

Ever since then I replaced all regread's with these functions. Theres even a function to encrypt the data you enter into the database.

#include<Array.au3>
#include<Crypt.au3>
#include<SQLite.au3>
#include<SQLite.dll.au3>
Global $DB, $NoUpdate = False;This means that pre-existing data is not to be updated.
Global $Tables[3] = ["ScriptData", "DataBase", "ThemeData"];this is your "$Table"
Global $DataBase = @DesktopDir & "\MyData.db"

If Not _StartUp($DataBase,$Tables) Then
    MsgBox(16,"Error","there was an error with the sqlite function",3)
    Exit
EndIf

_DataAddEx($Tables[1],"My_Script_Data","This is some data","Even mooo bata 4 jiew","TROLOLOL","ROFLCOPTERT","XDDDD") ; add some data table "DataBase"...
_DataAddEx($Tables[1],"My_Script_Data2","36754","15657","cindy","detroit","TEXAS")
_DataCheck($Tables[1])

Func _StartUp($DataBase,$Tables)
    _Crypt_Startup()
    _SQLite_Startup()
    If @error Then
        MsgBox(16, "ERROR", "SQLITE ERROR!!!")
        Return 0
    EndIf
    OnAutoItExitRegister("_My_Janitor")
    If Not FileExists($DataBase) Then
        $DB = _SQLite_Open($DataBase)
        For $i = 0 To UBound($Tables) - 1
            _SQLite_Exec($DB, "CREATE TABLE " & $Tables[$i] & " (Adress,Val1,Val2,Val3,Val4,Val5);");You can create more tables of different names depending on your needs.
        Next
        Return 2
    Else
        $DB = _SQLite_Open($DataBase)
    EndIf
    Return 1
EndFunc   ;==>_StartUp

Func _DataCheck($Table)
    Local $hQuery, $aRow, $i = 0, $Data
    _SQLite_Query(-1, "SELECT * FROM " & $Table & ";", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $i += 1
        $Data = _DataQueryEx($Table, $aRow[0],True)
        _ArrayDisplay($Data)
    WEnd
    Return 1
EndFunc   ;==>_DataCheck

Func _SetDataEx($Data, $Table, $Adress, $UKEY = 0x0006548)
    Local $Key, $CData
    _Crypt_Startup()
    $Key = _Crypt_DeriveKey($UKEY, $CALG_RC4)
    $CData = _Crypt_EncryptData($Data, $Key, $CALG_USERKEY)
    _DataAddEx($Table, $Adress, $CData)
    If @error Then Return @error
    _Crypt_DestroyKey($Key)
    _Crypt_Shutdown()
    Return 1
EndFunc   ;==>_SetDataEx

Func _GetDataEx($Table, $Adress, $UKEY = 0x0006548)
    Local $RData, $Key, $Data, $CData
    _Crypt_Startup()
    $Key = _Crypt_DeriveKey($UKEY, $CALG_RC4)
    $RData = _DataQueryEx($Table, $Adress)
    $CDta = _Crypt_DecryptData($RData, $Key, $CALG_USERKEY)
    If @error Then Return 0
    Local $Data = BinaryToString($CDta)
    If $Data = "" Then Return 0
    _Crypt_DestroyKey($Key)
    _Crypt_Shutdown()
    Return $Data
EndFunc   ;==>_GetDataEx

Func _DataAddEx($Table, $Adress, $Val1, $Val2 = "", $Val3 = "", $Val4 = "", $Val5 = "")
    Local $Data
    _SQLite_QuerySingleRow($DB, "SELECT Adress FROM " & $Table & " WHERE Adress='" & $Adress & "'", $Data)
    If $Data[0] <> "" Then; If there is an error here than its your fault... the data base doesn't exist
        ;If Not MsgBox(17, "Data exists", "Information for this file exists." & @CRLF & @CRLF & "Continue Operation?") = 1 Then Return 1
        If $NoUpdate Then Return 1
        _SQLite_Exec($DB, "UPDATE " & $Table & " SET Val1='" & $Val1 & "', Val2='" & $Val2 & "', Val3='" & $Val3 & "', Val4='" & $Val4 & "', Val5='" & $Val5 & "' WHERE Adress='" & $Adress & "'")
    Else
        _SQLite_Exec($DB, "INSERT INTO " & $Table & " (Adress,Val1,Val2,Val3,Val4,Val5) VALUES ('" & $Adress & "','" & $Val1 & "','" & $Val2 & "','" & $Val3 & "','" & $Val4 & "','" & $Val5 & "');")
    EndIf
    Return 1
EndFunc   ;==>_DataAddEx

Func _DataQueryEx($Table, $Adress, $Ar = False)
    Local $Ret
    If _SQLite_QuerySingleRow($DB, "SELECT * FROM " & $Table & " WHERE Adress='" & $Adress & "'", $Ret) == $SQLITE_OK Then ; =>"*"<= means all...
        If $Ret[0] == "" Then
            Return 0
        Else
            If $Ar Then Return $Ret
            If $Ret[1] = "" Or $Ret[1] = ' ' Then Return 0
            Return $Ret[1]
        EndIf
    EndIf
    Return 0
EndFunc   ;==>_DataQueryEx

Func _DataDel($Table, $Adress)
    Local $Ret
    _SQLite_QuerySingleRow($DB, "SELECT Adress FROM " & $Table & " WHERE Adress='" & $Adress & "'", $Ret)
    If $Ret[0] <> "" Then
        _SQLite_Exec($DB, "DELETE FROM " & $Table & " WHERE Adress='" & $Adress & "'")
    EndIf
EndFunc   ;==>_DataDel

Func _My_Janitor()
    _Crypt_Shutdown()
    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc   ;==>_My_Janitor

Edit:

Here is an example from the help documentation that shows you how to automate notepad.

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!n")
Edited by System238
Link to comment
Share on other sites

I'm going to assume that English isn't your first language, it ain't mine either.

First of all, "NotePad.exe" is an executable program/application that was designed to edit basic text files.

I will also make the assumption that when you typed "create a script for register and save data to a notepad" you actually meant to type "How should I go about writing a script that will launch notepad and enter some text into it and save it to a text file."

and I will also assume that "then create an other to login using that notepad data"" actually means "and how can I restart the process after a user logs on?".

If I am correct, the first step you should take in your quest to improve your familiarity with the syntax used by AutoIt3.exe is to open the "Scite" text editor that comes with "AutoIt" and look for the "help" button in the tool bar and lick it.

Some more buttons will appear, another button named "help" will be visible.

click on the help button again and a new window will appear, there will be a tab view area and one of those tabs will display the name "content", click on that button and go to the tree view area.

there will be an entry titles "Tutorials", in that area is your answer.

TL;DR

Use the help file..

1st i said sory for my bad english

2nd i'm just a newbie and is hard to understood from help

that's why i'm here if i could understood from help i won't come here :|

Link to comment
Share on other sites

Don't B sorry. We all had to start some were!

Try this BUT please note this is for demo purposes only!

#include <GUIConstantsEx.au3>
$GUI = GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
$Input1 = GUICtrlCreateInput("", 10, 5, 300, 20)
$passwordedit = GUICtrlCreateInput("", 10, 35, 300, 20)
$ButtonOk = GUICtrlCreateButton("Ok", 40, 75, 60, 20)
$Buttoncancel = GUICtrlCreateButton("Cancel", 40, 95, 60, 20)
GUISetState()
If FileExists("SecretPassword.txt") Then
    $file = FileOpen("SecretPassword.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    $ID = FileReadLine("SecretPassword.txt", 1)
    $PW = FileReadLine("SecretPassword.txt", 2)
    GUICtrlSetData($Input1, $ID)
    GUICtrlSetData($passwordedit, $PW)
    FileClose($file)
EndIf
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Buttoncancel
            Exit
        Case $ButtonOk
            $ID = GUICtrlRead($Input1)
            $PW = GUICtrlRead($passwordedit)
            ;You might want to do some testing first !!!!!!!!
            GUISetState(@SW_HIDE, $GUI)
                        MsgBox(0, "", "Register Succesfull", 2)
            ExitLoop
    EndSwitch
WEnd
$file = FileOpen("SecretPassword.txt", 2); OverWrite previous info
FileWrite($file, $ID & @CRLF)
FileWrite($file, $PW)
FileClose($file)
MsgBox(0, '', 'Now open notepad and show your info!' & @CRLF & 'This is not recomended but demonstrates the question')
ShellExecute("SecretPassword.txt")
Link to comment
Share on other sites

nice work but how can i use this to login after register.. this script only save dada

i need some explains about string ;)

there is my scripts how can i use string to save id and pw with other variabile every time i use script

EDIT:system ty for tutorial nice work!:>

sry for bad english :unsure:

Register.au3

login.au3

Edited by pl4y0n
Link to comment
Share on other sites

nice work but how can i use this to login after register.. this script only save dada

i need some explains about string :unsure:

The example script above actually have what you need. If it does find the file it will fill the Id and Pw in for you.

You just need to do the bit from your login script to validate the ID and PW.

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