Jump to content

Parse?


Gil
 Share

Recommended Posts

I have a file called automodem.pbk and this file is a phonebook for my dialup connections. I am trying to write a script that will read the entry names in it.

For example:

I have an entry created called ISP

In the file it is [iSP]

I want to create a gui with a dropdown menu that will display the ISP in it.

With that said, the script needs to read the automodem.pbk file for all [ ] entries and list them in the dropdown menu. So when I launch my app and click on the dropdown menu it will be as follows:

Select Entry

-ISP

-ISP2

-ISP3

example of automodem.pbk:

[iSP]

Encoding=1

Type=1

AutoLogon=0

UseRasCredentials=1

DialParamsUID=951062625

Guid=4D4B6A0217DAAF4A997482A606E70A1B

BaseProtocol=1

VpnStrategy=0

ExcludedProtocols=0

LcpExtensions=1

DataEncryption=8

SwCompression=1

NegotiateMultilinkAlways=0

SkipNwcWarning=0

SkipDownLevelDialog=0

SkipDoubleDialDialog=0

DialMode=1

DialPercent=75

DialSeconds=120

HangUpPercent=10

HangUpSeconds=120

OverridePref=15

RedialAttempts=3

RedialSeconds=60

IdleDisconnectSeconds=0

RedialOnLinkFailure=0

CallbackMode=0

CustomDialDll=

CustomDialFunc=

CustomRasDialDll=

AuthenticateServer=0

ShareMsFilePrint=0

BindMsNetClient=1

SharedPhoneNumbers=1

GlobalDeviceSettings=0

PrerequisiteEntry=

PrerequisitePbk=

PreferredPort=

PreferredDevice=

PreviewUserPw=1

PreviewDomain=0

PreviewPhoneNumber=1

ShowDialingProgress=1

ShowMonitorIconInTaskBar=1

CustomAuthKey=-1

AuthRestrictions=632

TypicalAuth=1

IpPrioritizeRemote=1

IpHeaderCompression=1

IpAddress=0.0.0.0

IpDnsAddress=0.0.0.0

IpDns2Address=0.0.0.0

IpWinsAddress=0.0.0.0

IpWins2Address=0.0.0.0

IpAssign=1

IpNameAssign=1

IpFrameSize=1006

IpDnsFlags=0

IpNBTFlags=1

TcpWindowSize=0

UseFlags=0

IpSecFlags=0

IpDnsSuffix=

NETCOMPONENTS=

ms_server=0

ms_msclient=1

MEDIA=serial

Port=COM1

ConnectBPS=0

DEVICE=modem

PhoneNumber=

AreaCode=

CountryCode=1

CountryID=1

UseDialingRules=0

Comment=

LastSelectedPhone=0

PromoteAlternates=0

TryNextAlternateOnFail=1

HwFlowControl=0

Protocol=0

Compression=0

Speaker=1

MdmProtocol=0

[iSP2]

Encoding=1

Type=1

AutoLogon=0

UseRasCredentials=1

DialParamsUID=951062625

Guid=4D4B6A0217DAAF4A997482A606E70A1B

BaseProtocol=1

VpnStrategy=0

ExcludedProtocols=0

LcpExtensions=1

DataEncryption=8

SwCompression=1

NegotiateMultilinkAlways=0

SkipNwcWarning=0

SkipDownLevelDialog=0

SkipDoubleDialDialog=0

DialMode=1

DialPercent=75

DialSeconds=120

HangUpPercent=10

HangUpSeconds=120

OverridePref=15

RedialAttempts=3

RedialSeconds=60

IdleDisconnectSeconds=0

RedialOnLinkFailure=0

CallbackMode=0

CustomDialDll=

CustomDialFunc=

CustomRasDialDll=

AuthenticateServer=0

ShareMsFilePrint=0

BindMsNetClient=1

SharedPhoneNumbers=1

GlobalDeviceSettings=0

PrerequisiteEntry=

PrerequisitePbk=

PreferredPort=

PreferredDevice=

PreviewUserPw=1

PreviewDomain=0

PreviewPhoneNumber=1

ShowDialingProgress=1

ShowMonitorIconInTaskBar=1

CustomAuthKey=-1

AuthRestrictions=632

TypicalAuth=1

IpPrioritizeRemote=1

IpHeaderCompression=1

IpAddress=0.0.0.0

IpDnsAddress=0.0.0.0

IpDns2Address=0.0.0.0

IpWinsAddress=0.0.0.0

IpWins2Address=0.0.0.0

IpAssign=1

IpNameAssign=1

IpFrameSize=1006

IpDnsFlags=0

IpNBTFlags=1

TcpWindowSize=0

UseFlags=0

IpSecFlags=0

IpDnsSuffix=

NETCOMPONENTS=

ms_server=0

ms_msclient=1

MEDIA=serial

Port=COM1

ConnectBPS=0

DEVICE=modem

PhoneNumber=

AreaCode=

CountryCode=1

CountryID=1

UseDialingRules=0

Comment=

LastSelectedPhone=0

PromoteAlternates=0

TryNextAlternateOnFail=1

HwFlowControl=0

Protocol=0

Compression=0

Speaker=1

MdmProtocol=0

[iSP3]

Encoding=1

Type=1

AutoLogon=0

UseRasCredentials=1

DialParamsUID=951062625

Guid=4D4B6A0217DAAF4A997482A606E70A1B

BaseProtocol=1

VpnStrategy=0

ExcludedProtocols=0

LcpExtensions=1

DataEncryption=8

SwCompression=1

NegotiateMultilinkAlways=0

SkipNwcWarning=0

SkipDownLevelDialog=0

SkipDoubleDialDialog=0

DialMode=1

DialPercent=75

DialSeconds=120

HangUpPercent=10

HangUpSeconds=120

OverridePref=15

RedialAttempts=3

RedialSeconds=60

IdleDisconnectSeconds=0

RedialOnLinkFailure=0

CallbackMode=0

CustomDialDll=

CustomDialFunc=

CustomRasDialDll=

AuthenticateServer=0

ShareMsFilePrint=0

BindMsNetClient=1

SharedPhoneNumbers=1

GlobalDeviceSettings=0

PrerequisiteEntry=

PrerequisitePbk=

PreferredPort=

PreferredDevice=

PreviewUserPw=1

PreviewDomain=0

PreviewPhoneNumber=1

ShowDialingProgress=1

ShowMonitorIconInTaskBar=1

CustomAuthKey=-1

AuthRestrictions=632

TypicalAuth=1

IpPrioritizeRemote=1

IpHeaderCompression=1

IpAddress=0.0.0.0

IpDnsAddress=0.0.0.0

IpDns2Address=0.0.0.0

IpWinsAddress=0.0.0.0

IpWins2Address=0.0.0.0

IpAssign=1

IpNameAssign=1

IpFrameSize=1006

IpDnsFlags=0

IpNBTFlags=1

TcpWindowSize=0

UseFlags=0

IpSecFlags=0

IpDnsSuffix=

NETCOMPONENTS=

ms_server=0

ms_msclient=1

MEDIA=serial

Port=COM1

ConnectBPS=0

DEVICE=modem

PhoneNumber=

AreaCode=

CountryCode=1

CountryID=1

UseDialingRules=0

Comment=

LastSelectedPhone=0

PromoteAlternates=0

TryNextAlternateOnFail=1

HwFlowControl=0

Protocol=0

Compression=0

Speaker=1

MdmProtocol=0

Thanks in advance for any direction or help.

Edited by Gil
Link to comment
Share on other sites

I just made up a script off the top of my head (uses txt instead of ini) to test the ini functions. As long as it's in the right format, you'll be ok.

$fileo = FileOpen ("D:\testini.txt", 2)

FileWriteLine ($fileo, "[ISP]")
FileWriteLine ($fileo, "CurrentISP=SBC")
FileWriteLine ($fileo, "[ISP2]")
FileWriteLine ($fileo, "BackupISP=AOL")
FileWriteLine ($fileo, "[ISP3]")
FileWriteLine ($fileo, "SecondaryBackup=none")
FileClose ($fileo)

MsgBox (0, "", IniRead ("D:\testini.txt", "ISP", "CurrentISP", "") & @CRLF & IniRead ("D:\testini.txt", "ISP2", "BackupISP", "") _ 
& @CRLF & IniRead ("D:\testini.txt", "ISP3", "SecondaryBackup", ""))

Works with all files - I just tested it with extensions abc and fdjsk.

Edited by greenmachine
Link to comment
Share on other sites

OK I can use the IniReadSectionNames Function:

$var = IniReadSectionNames("automodem.pbk")

If @error Then

MsgBox(4096, "", "Error occured, probably no INI file.")

Else

For $i = 1 To $var[0]

MsgBox(4096, "", $var[$i])

Next

EndIf

This displays what I need in a msgbox one at a time.

How can I make that information ($var) be part (displayed) of a drop down menu (CrtlCreateComboBox)?

Here is what I have so far:

#include <GUIConstants.au3>

GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

$read = IniReadSectionNames("automodem.pbk")

$combo = GUICtrlCreateCombo ("", 10,10) ; create first item

GUICtrlSetData ( -1, "","")

GUISetState ()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

I would think that I could just add the $var to the GUICtrlSetData ($combo, $read)?

It looks like the IniReadSectionNames is reading the information but not storing it for input later.

Dont know, STUMPED.

Thanks.

Link to comment
Share on other sites

OK I can use the IniReadSectionNames Function:

$var = IniReadSectionNames("automodem.pbk")

If @error Then

MsgBox(4096, "", "Error occured, probably no INI file.")

Else

For $i = 1 To $var[0]

MsgBox(4096, "", $var[$i])

Next

EndIf

This displays what I need in a msgbox one at a time.

How can I make that information ($var) be part (displayed) of a drop down menu (CrtlCreateComboBox)?

Here is what I have so far:

#include <GUIConstants.au3>

GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

$read = IniReadSectionNames("automodem.pbk")

$combo = GUICtrlCreateCombo ("", 10,10) ; create first item

GUICtrlSetData ( -1, "","")

GUISetState ()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

I would think that I could just add the $var to the GUICtrlSetData ($combo, $read)?

It looks like the IniReadSectionNames is reading the information but not storing it for input later.

Dont know, STUMPED.

Thanks.

You're getting there. All you have to do to get the section names into a combo box is change GUICtrlSetData(-1,"","") to:

For $i = 1 To $read[0]
    GUICtrlSetData ( -1, $read[$i] & "|","")
Next

However, I get the feeling you're going to want more than just the names of the sections, so I'll give you this tip for reading the section - when you read the section, it stringsplits the inputs with "=", so you end up with a 2-dimensional array.

$var = IniReadSectionNames("automodem.pbk")
$VarPart2 = IniReadSection ("automodem.pbk", $var[1])

In this case, $VarPart2 is a 2-dimensional array containing all the ini info.

Link to comment
Share on other sites

That worked!

I have tried to define the selection that was selected in the combo box to be $entry, with no luck.

I want to define the selection, say I selected ISP and then run a function based on the button say delete.

when the delete key was pressed it would launch the following function:

Func delete()

Run ( @SystemDir & "\rasphone -f automodem.pbk -r" & $entryname )

EndFunc

So it will delete the entry ISP.

Here is the total script.

#include <GUIConstants.au3>

;creating gui window

GUICreate("Phone Book",320,150)

;creating gui window icon

GUISetIcon ("modem.ico")

;created group entry

$group = GUICtrlCreateGroup ("Entries", 10, 20, 300, 110)

;create combo box

$combo = GUICtrlCreateCombo ("", 20,40,280,200) ; create first item

;reads the automodem.pbk file, just section names

$read = IniReadSectionNames("automodem.pbk")

For $i = 1 To $read[0]

GUICtrlSetData ( -1, $read[$i] & "|","")

Next

;creating buttons for main screen

;just that creating buttons

$createbutton = GUICtrlCreateButton ("Create",20,100,70,20) ;325

$editbutton = GUICtrlCreateButton ("Edit",90,100,70,20)

$deletebutton = GUICtrlCreateButton ("Delete",160,100,70,20)

$exitbutton = GUICtrlCreateButton ("Exit",230,100,70,20)

; setting $entryname variable

;$entryname = ******************************************** Need help setting the results of the combo box once selected....

GUISetState ()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $createbutton

create()

Case $msg = $editbutton

edit()

Case $msg = $deletebutton

delete()

EndSelect

If $msg = $GUI_EVENT_CLOSE Or $msg = $exitbutton Then ExitLoop

WEnd

GUIDelete()

Exit

Func create()

Run ( @SystemDir & "\rasphone -f automodem.pbk -a entryname")

WinWaitActive("New Connection Wizard")

Send("{Enter}")

EndFunc

Func edit()

Run ( @SystemDir & "\rasphone -f automodem.pbk -e" & $entryname)

EndFunc

Func delete()

Run ( @SystemDir & "\rasphone -f automodem.pbk -r" & $entryname )

EndFunc

---------------------------------------------------------------------------------------------------------------------------

GOT IT WORKING, THANKS ALL.

Edited by Gil
Link to comment
Share on other sites

  • Moderators

[ code][ /code] tags are an Awsome thing!! :lmao:

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

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