Sign in to follow this  
Followers 0
no4ndth3n

INI Read Error

3 posts in this topic

I am trying to read a setting from an INI file. If I output the INI information BEFORE I update the LISTVIEW control, then it reads the information fine. However, if I update the LISTVIEW control with the PC list first, the INI information will not display. It outputs blanks.

I have a file C:\pcs.txt that contains a list of PC's

I have an ini file that contains

[PSEXEC]
exe=psexec.exe
folder=@scriptDir

[Java 1.4.2_12]
command=C:\Documents and Settings\eito.ARROWHEADCU\Desktop\j2re-1_4_2_12-windows-i586-p.exe
arguments=/s /v" /qn IEXPLORE=0 MOZILLA=0 JAVAUPDATE=0 WEBSTARTICON=0 AgreeToLicense=1 EULA=1"

Now, if I display the results from INIRead before I select the input file, I can display the INI values, but if I upload the file at any time, the values are overwritten with blanks.

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GuiList.au3>
#include <GuiStatusBar.au3>

Opt("GuiOnEventMode",1)

FileInstall("C:\psexec.exe",@scriptDir & "\psexec.exe")

;$PSEXEC = "psexec.exe"
$PSEXEC = IniRead("config.ini","PSEXEC","exe","psexec.exe")

;$PSEXEC_PATH = "C:\"
$PSEXEC_PATH = Execute(IniRead("config.ini","PSEXEC","folder",""))

;MsgBox(0,'path',$PSEXEC)
;MsgBox(0,'path',$PSEXEC_PATH)

$WIDTH                  = 640
$HEIGHT                 = 480
$MAIN_GUI               = GUICreate("ACU Remote Installer",$WIDTH,$HEIGHT,-1,-1)

$LISTVIEW               = GUICtrlCreateListView("PC|Status|Exit Code",5,15,$WIDTH-400,$HEIGHT-50)
_GUICtrlListViewSetColumnWidth($LISTVIEW,0,75)
_GUICtrlListViewSetColumnWidth($LISTVIEW,1,75)
_GUICtrlListViewSetColumnWidth($LISTVIEW,2,75)

$INPUT_FILE_LABEL       = GUICtrlCreateLabel("PC List:",260,25,50,20)
$INPUT_FILE_INPUT       = GUICtrlCreateInput("",300,22,300,20)
$INPUT_FILE_BUTTON      = GUICtrlCreateButton("...",605,22,30,20)

$PACKAGE_GROUP          = GUICtrlCreateGroup("Software",270,100,350,150)

$PACKAGE_LIST           = GUICtrlCreateList("",295,125,300,100,$LBS_SORT)
updatePackageList()

Global $STATUS_BAR_EDGE[3]  = [300,400,-1]
Global $STATUS_BAR_TEXT[3]      = ["1","","Install ratio"]
$STATUS_BAR             = _GUICtrlStatusBarCreate($MAIN_GUI,$STATUS_BAR_EDGE,$STATUS_BAR_TEXT)

$PB_1                   = _GUICtrlStatusBarCreateProgress($STATUS_BAR,0,$PBS_SMOOTH)

$RUN_BUTTON             = GUICtrlCreateButton("Install",300,300,100,20)

Global $PACKAGE_TO_INSTALL ;= _GUICtrlListGetText($PACKAGE_LIST,_GUICtrlListSelectedIndex($PACKAGE_LIST))
Global $exePath             ;= IniRead("config.ini",$PACKAGE_TO_INSTALL,"command","")
Global $args                ;= IniRead("config.ini",$PACKAGE_TO_INSTALL,"arguments","")

GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUICtrlSetOnEvent($INPUT_FILE_BUTTON,"getFile")
GUICtrlSetOnEvent($RUN_BUTTON,"go")
GUICtrlSetOnEvent($PACKAGE_LIST,"updateList")

GUISetState()

while 1
    Sleep(10)
WEnd

Func close()
    Exit
EndFunc

Func getFile()
    Local $fileName = FileOpenDialog("Select input file",@Desktopdir,"All files (*.*)")
    
    If $fileName <> "" Then
        GUICtrlSetData($INPUT_FILE_INPUT,$fileName)
        updateListView()
    EndIf
EndFunc

Func updateListView()

    local $infile = FileOpen(GUICtrlRead($INPUT_FILE_INPUT),0)

    while 1
        $line = FileReadLine($infile)
        If @error = -1 Then ExitLoop
        GUICtrlCreateListViewItem($line & "|" & "pending|",$LISTVIEW)
    WEnd

    FileClose($infile)

EndFunc

Func go()
        
    GUICtrlSetState($RUN_BUTTON,$GUI_DISABLE)
    
    Local $PACKAGE_TO_INSTALL   = _GUICtrlListGetText($PACKAGE_LIST,_GUICtrlListSelectedIndex($PACKAGE_LIST))
    
    Local $pcCount = _GUICtrlListViewGetItemCount($LISTVIEW)

    MsgBox(0,'',$PACKAGE_TO_INSTALL)
    
    MsgBox(0,$exePath,$args)
    MsgBox(0,'',@comspec & ' /c ' & $PSEXEC & ' \\pc1707  -c "' & $exePath & '" ' & $args)
    
    For $i=0 to $pcCount-1
        
        $pc = _GUICtrlListViewGetItemText($LISTVIEW,$i,0)
        
        _GUICtrlListViewSetItemText($LISTVIEW,$i,1,"Installing...")
    
    ;WORKS $1 = RunWait(@comspec & ' /c ' & $PSEXEC & ' \\' & $pc & ' -c "C:\documents and settings\eito.ARROWHEADCU\Desktop\j2re-1_4_2_12-windows-i586-p.exe" /s /v" /qn IEXPLORE=0 MOZILLA=0 JAVAUPDATE=0 WEBSTARTICON=0 AgreeToLicense=1 EULA=1"',$PSEXEC_PATH,@SW_HIDE)
    ;$1 = RunWait(@comspec & ' /c ' & $PSEXEC & ' \\' & $pc & ' -c "' & $exePath & '" ' & $args,$PSEXEC_PATH,@SW_HIDE)
        
        MsgBox(0,'',@comspec & ' /c ' & $PSEXEC & ' \\' & $pc & ' -c "' & $exePath & '" ' & $args)
    ;MsgBox(0,'',@comspec & ' /c "C:\Documents and Settings\eito.ARROWHEADCU\Desktop\Scripting\pstools\psexec.exe" \\' & $pc & ' -c "C:\documents and settings\eito.ARROWHEADCU\Desktop\j2re-1_4_2_12-windows-i586-p.exe" /s /v" /qn IEXPLORE=0 MOZILLA=0 JAVAUPDATE=0 WEBSTARTICON=0 AgreeToLicense=1 EULA=1"')
    ;MsgBox(0,'Exit Code',$1)
        _GUICtrlListViewSetItemText($LISTVIEW,$i,1,"Finished")
        if $1 <> 0 Then
            _GUICtrlListViewSetItemText($LISTVIEW,$i,2,"Error")
        Else
            _GUICtrlListViewSetItemText($LISTVIEW,$i,2,$1)
        EndIf
        
    Next
    
    GUICtrlSetState($RUN_BUTTON,$GUI_ENABLE)
EndFunc

Func updatePackageList()
    Dim $packages = IniReadSectionNames("config.ini")
    
    For $i=1 to $packages[0]
        If $packages[$i] = "PSEXEC" Then
        ; nothing
        Else
            GUICtrlSetData($PACKAGE_LIST,$packages[$i] & "|")
        EndIf
        
    Next
    
EndFunc

Func updateList()
;udpate every click
    $PACKAGE_TO_INSTALL     = _GUICtrlListGetText($PACKAGE_LIST,_GUICtrlListSelectedIndex($PACKAGE_LIST))
    $exePath                = IniRead("config.ini",$PACKAGE_TO_INSTALL,"command","")
    $args                   = IniRead("config.ini",$PACKAGE_TO_INSTALL,"arguments","")
    MsgBox(0,'Update:',$PACKAGE_TO_INSTALL & @CRLF & $exePath & @CRLF & $args)
EndFunc


#cs

psexec \\computer -c "C:\Path to Java\File" /s /v" /qn IEXPLORE=0 MOZILLA=0 JAVAUPDATE=0 WEBSTARTICON=0 AgreeToLicense=1 EULA=1"

#ce

Share this post


Link to post
Share on other sites



You don't specify an explicit path to the INI file so it looks in the working directory. FileOpenDialog() changes the working directory, ergo, you're looking for an INI file in a completely different location than you think.

The moral of the story: Always specify the full path to your files.

Share this post


Link to post
Share on other sites

You don't specify an explicit path to the INI file so it looks in the working directory. FileOpenDialog() changes the working directory, ergo, you're looking for an INI file in a completely different location than you think.

The moral of the story: Always specify the full path to your files.

Ah yes! Thank you very much. That would have taken me quite a while to figure out.

Share this post


Link to post
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
Sign in to follow this  
Followers 0