Jump to content

Can't write to ini file


max23ed
 Share

Recommended Posts

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Debug.au3>

#Region ### START Koda GUI section ### Form=c:\users\ali\downloads\!testproject\form1.kxf
Global $Form1_1 = GUICreate("Form1", 956, 667, -1, -1)
Global $Browsbtn = GUICtrlCreateButton("Browse a setup", 776, 64, 123, 25)
Global $locationtxt = GUICtrlCreateInput("", 584, 64, 169, 21)
Global $showbtn = GUICtrlCreateButton("Add", 776, 104, 123, 25)
Global $silent_list = GUICtrlCreateList("", 32, 48, 241, 552)
Global $record_list = GUICtrlCreateList("", 320, 48, 249, 552)
Global $aaaaaa = GUICtrlCreateLabel("Silent installs", 40, 16, 64, 17)
Global $Label1 = GUICtrlCreateLabel("Non-Silent installs", 328, 16, 87, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
global $filename
global $abc
global $file_usage
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browsbtn

            GUICtrlSetData($locationtxt, FileOpenDialog("Select the program to analyze", '', "Supported files (*.exe;*.msi;*.reg;*.inf)|Executable Files (*.exe)|Microsoft Installer files (*.msi)|Registry files (*.reg)|Inf files (*.inf)", 3))
            Sleep(100)
            $abc = GUICtrlRead($locationtxt)
            $filename = StringTrimLeft($abc, StringInStr($abc, '\', 0, -1))


        Case $showbtn
             IniWrite("configg.ini", $filename, "switch", "abc")
            Run("ussf.exe " & $abc, "", @SW_HIDE)
            WinWait('USSF', 'Universal Silent Switch Finder',-1)
            WinSetState("USSF", "Universal Silent Switch Finder", @SW_HIDE)
            ; ############################################## Config.ini values ##########################################
            ; Looping to get the ini values
            Local $file_extension
            WinWait("USSF")
            Do
                $file_extension = ControlGetText("USSF", "", "Edit2")
                $file_type = ControlGetText("USSF", "", "Edit3")
                $file_usage = ControlGetText("USSF", "", "Edit4")
            Until $file_extension <> "Loading..." And $file_extension <> "" And $file_type <> "Loading..." And $file_type <> "" And $file_usage <> "Loading..." And $file_usage <> ""
           sleep(5000)
           ;Here IniWrite is not working idk why 
             IniWrite("config.ini", $filename, "switch", $file_usage)
             

    EndSwitch
WEnd

Hi, i don't know why its not writing. i need it in ini format please help thanks.

Link to comment
Share on other sites

  • Developers

You do not have any error checking for the IniWrite() function, but my guess would be that the INI file is created in the directory which was selected by the  FileOpenDialog() statement as that will change the workdir.
Change the IniWrite statement to:

IniWrite(@scriptdir & "\config.ini", $filename, "switch", $file_usage)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
Just now, max23ed said:

Thanks Jos, when i provide the full path to the ini file, its working fine. i did try what you have suggested but still didn't work.

 

mmm ...  this is a very confusing post: It works ...but is doesn't?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I am still confused whether you are asking a question or making a statement here and don't really understand it ..... sorry. :) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I'm sorry i poor at explaining. 

This is working, it did write into the ini ---> 

IniWrite("C:\Users\Desktop\projectC\config.ini", $filename, "switch", $file_usage)

however this did not work 

IniWrite(@scriptdir & "\config.ini", $filename, "switch", $file_usage)

can i somehow get the full path so if i run this project in any machine it will still work.

Link to comment
Share on other sites

  • Developers

The second statement should work fine when the script is stored in "C:\Users\Desktop\projectC\".
Is that the case?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
Just now, max23ed said:

idk, tried the full path again and didn't work, maybe a bug?

no ...  there is a problem with the script or rights to access the file.
You need to use some debugging to check what is happening, so try running this version and tell us what the shown information is in the MessageBox:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Debug.au3>

#Region ### START Koda GUI section ### Form=c:\users\ali\downloads\!testproject\form1.kxf
Global $Form1_1 = GUICreate("Form1", 956, 667, -1, -1)
Global $Browsbtn = GUICtrlCreateButton("Browse a setup", 776, 64, 123, 25)
Global $locationtxt = GUICtrlCreateInput("", 584, 64, 169, 21)
Global $showbtn = GUICtrlCreateButton("Add", 776, 104, 123, 25)
Global $silent_list = GUICtrlCreateList("", 32, 48, 241, 552)
Global $record_list = GUICtrlCreateList("", 320, 48, 249, 552)
Global $aaaaaa = GUICtrlCreateLabel("Silent installs", 40, 16, 64, 17)
Global $Label1 = GUICtrlCreateLabel("Non-Silent installs", 328, 16, 87, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $filename
Global $abc
Global $file_usage
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browsbtn

            GUICtrlSetData($locationtxt, FileOpenDialog("Select the program to analyze", '', "Supported files (*.exe;*.msi;*.reg;*.inf)|Executable Files (*.exe)|Microsoft Installer files (*.msi)|Registry files (*.reg)|Inf files (*.inf)", 3))
            Sleep(100)
            $abc = GUICtrlRead($locationtxt)
            $filename = StringTrimLeft($abc, StringInStr($abc, '\', 0, -1))


        Case $showbtn
            IniWrite("configg.ini", $filename, "switch", "abc")
            Run("ussf.exe " & $abc, "", @SW_HIDE)
            WinWait('USSF', 'Universal Silent Switch Finder', -1)
            WinSetState("USSF", "Universal Silent Switch Finder", @SW_HIDE)
            ; ############################################## Config.ini values ##########################################
            ; Looping to get the ini values
            Local $file_extension
            WinWait("USSF")
            Do
                $file_extension = ControlGetText("USSF", "", "Edit2")
                $file_type = ControlGetText("USSF", "", "Edit3")
                $file_usage = ControlGetText("USSF", "", "Edit4")
            Until $file_extension <> "Loading..." And $file_extension <> "" And $file_type <> "Loading..." And $file_type <> "" And $file_usage <> "Loading..." And $file_usage <> ""
            Sleep(5000)
            ;Here IniWrite is not working idk why
            $rc = IniWrite(@ScriptDir & "\config.ini", $filename, "switch", $file_usage)
            MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Ini file:' & @CRLF & @ScriptDir & "\config.ini" & @CRLF & @CRLF & 'RC:' & $rc & @CRLF & '@Error:' & @error) ;### Debug MSGBOX
    EndSwitch
WEnd

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

I don't see any reason why the sleep is needed. What info is shown when it doesn't work?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×
×
  • Create New...