Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading and Writing variables to a file using AutoIT

Posted on 2011-03-22
5
Medium Priority
?
3,147 Views
Last Modified: 2013-11-13
Hello

 I am trying to create a password vault for storing usernames and passwords.
 using AutoIT.

So far I have:

#include <GUIConstantsEx.au3>
Global $ini = @AppDataDir & "\Meerecat\PasswordVault\PassVlt.ini"
Opt("GUIOnEventMode", 1)

GUICreate("Form1", 228, 215, 192, 124)
$program = GUICtrlCreateInput("", 8, 32, 169, 21)
$Label1 = GUICtrlCreateLabel("Program / Website", 8, 56, 93, 17)
$username = GUICtrlCreateInput("", 12, 84, 169, 21)
$Label2 = GUICtrlCreateLabel("Username", 16, 113, 52, 17)
$password = GUICtrlCreateInput("", 12, 141, 169, 21)
$Label3 = GUICtrlCreateLabel("Password", 12, 170, 50, 17)
$button = GUICtrlCreateButton("Save", 12, 180, 50, 17)
$read = GUICtrlCreateButton("Read", 12, 200, 50, 17)
GUICtrlSetOnEvent($button, "_Write")
GUICtrlSetOnEvent($read, "_Read")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
While 1
    Sleep(1000) ; 
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Write()
IniWrite ( $ini, GUICtrlRead($program), GUICtrlRead($username), GUICtrlRead($password ))
EndFunc

Open in new window


I then need an Input box where the user types the $program variable and it displays the $username and $password variables in a message box.  I have tried the following to test the iniread but it's not working:

Func _Read()
    $read = IniRead  ( $ini, GUICtrlRead($program), GUICtrlRead($username), GUICtrlRead($password ))
MsgBox(4096, "Result", $read)
EndFunc

Open in new window


Can anybody suggest a better way of doing this?

Many Thanks
0
Comment
Question by:JakeSpencer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:matrixnz
ID: 35187888
The @AppDataDir & "\Meerecat\PasswordVault' folder must exist, use something like the following at the top of the script:

If FileExists(@AppDataDir & '\Meerecat\PasswordVault') = 0 Then
  DirCreate(@AppDataDir & '\Meerecat\PasswordVault')
EndIf

0
 

Author Comment

by:JakeSpencer
ID: 35187933
Hello

It does exist, and write's the variables to the ini file as expected.  I just can't work out how to get te information back.

Thanks
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 35187946
Writing something for you now.
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 2000 total points
ID: 35188273
Quick Script which I hopefully you can build on.

Cheers
#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>

Global $INI_INFO = @AppDataDir & '\Meerecat\PasswordVault\PassVlt.ini'
If FileExists(@AppDataDir & '\Meerecat\PasswordVault') = 0 Then DirCreate(@AppDataDir & '\Meerecat\PasswordVault')

GUICreate("Form", 350, 315)
	GUICtrlCreateLabel('Program / Website', 10, 10, 100, 20)
	$GUI_INFO = GUICtrlCreateInput('', 110, 10, 200, 20)
	GUICtrlCreateLabel('Username', 10, 35, 100, 20)
	$GUI_USER = GUICtrlCreateInput('', 110, 35, 200, 20)
	GUICtrlCreateLabel('Password', 10, 60, 100, 20)
	$GUI_PWRD = GUICtrlCreateInput('', 110, 60, 200, 20)
	$BTN_SAVE = GUICtrlCreateButton('Save', 260, 85, 50, 20)
	GUICtrlCreateLabel('Password List', 10, 110, 100, 20)
	$GUI_READ = GUICtrlCreateCombo('Check', 110, 110, 200, 20, $CBS_DROPDOWNLIST + $CBS_SORT)
GUISetState()

_FNC_READ()

While 1
	$msg = GUIGetMsg()
	Switch $msg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $BTN_SAVE
			IniWrite($INI_INFO, GUICtrlRead($GUI_INFO), 'USERNAME', GUICtrlRead($GUI_USER))
			IniWrite($INI_INFO, GUICtrlRead($GUI_INFO), 'PASSWORD', GUICtrlRead($GUI_PWRD))
			_FNC_READ()
		Case $GUI_READ
			If GUICtrlRead($GUI_READ) <> 'Check' Or GUICtrlRead($GUI_READ) > 0 Then
				GUICtrlSetData($GUI_INFO, GUICtrlRead($GUI_READ))
				GUICtrlSetData($GUI_USER, IniRead($INI_INFO, GUICtrlRead($GUI_READ), 'USERNAME', 'UNKNOWN'))
				GUICtrlSetData($GUI_PWRD, IniRead($INI_INFO, GUICtrlRead($GUI_READ), 'PASSWORD', 'UNKNOWN'))
			EndIf
			If GUICtrlRead($GUI_READ) <> 'Check' Or GUICtrlRead($GUI_READ) > 0 Then GUICtrlCreateEdit(IniRead($INI_INFO, GUICtrlRead($GUI_READ), 'USERNAME', 'UNKNOWN') & @CRLF & IniRead($INI_INFO, GUICtrlRead($GUI_READ), 'PASSWORD', 'UNKNOWN'), 110, 135, 200, 100)
	EndSwitch
WEnd

Func _FNC_READ()
	Local $INI_READ
	Local $VAR_READ
	If FileExists($INI_INFO) Then
		$INI_READ = IniReadSectionNames($INI_INFO)
		If IsArray($INI_READ) Then
			$VAR_READ = _ArrayToString($INI_READ, '|', 1)
			GUICtrlSetData($GUI_READ, $VAR_READ)
		EndIf
	EndIf
EndFunc

Open in new window

0
 

Author Comment

by:JakeSpencer
ID: 35188348
Hello

Many thanks for this.  Gives me a place to start and plenty to work from.

Many thanks again
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question