gcue Posted March 24, 2008 Share Posted March 24, 2008 how do i create a combobox to read from an ini? thanks. Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 24, 2008 Share Posted March 24, 2008 (edited) how do i create a combobox to read from an ini?thanks.Post the .ini and post a list of what you want in the combobox Edited March 24, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
gcue Posted March 24, 2008 Author Share Posted March 24, 2008 and i would only like to display the first value of each -- "ANDS_ESERV" [ASSETS] ANDS_ESERV=d0090775 ANDS_ETS=d0090774 DLG_ESERV=d0075934 DLG_ETS=d0049852 Link to comment Share on other sites More sharing options...
Swift Posted March 24, 2008 Share Posted March 24, 2008 (edited) IniReadSectionNames();Returns an Array with the names in it. $var = IniReadSectionNames("ini.ini") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] Msgbox(0, "", $var[$i]) Next EndIf That should help you out a little. Edited March 24, 2008 by R6V2 Link to comment Share on other sites More sharing options...
gcue Posted March 24, 2008 Author Share Posted March 24, 2008 right but how do i get the combobox to read that? i dont see a spot where i can plug in a variable for the array. IniReadSectionNames();Returns an Array with the names in it. $var = IniReadSectionNames("ini.ini") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] Msgbox(0, "", $var[$i]) Next EndIf That should help you out a little. Link to comment Share on other sites More sharing options...
Swift Posted March 24, 2008 Share Posted March 24, 2008 Ok, you use: Instead of the messagebox in the for/next loop, use like: GUICtrlSetData(-1, $Var[$i] & "|") That would set the data, if you use something like that it will work! Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 24, 2008 Share Posted March 24, 2008 (edited) This works with the squirrely.ini listed below it: $moneyGui = GUICreate("Big Bucks", 244, 100) $arr = IniReadSection("squirrely.ini", "ASSETS") If @error Then MsgBox(0,"","Error reading the 'ASSETS' section on line 2") Exit Else GUICtrlCreateCombo($arr[1][0], 10, 10); create combobox and set first item For $i = 2 To $arr[0][0] GUICtrlSetData(-1, $arr[$i][0]); add other items and set a new default control Next EndIf GUISetState() While 1 Sleep(30) $msg = GUIGetMsg() If $msg = -3 Then ExitLoop WEnd squirrely.ini - must be in same directory for the above code to work: [ASSETS] MeAndYourMoney=$MoreThanGod YouAndMyMoney=$CantHappen DoughAndBadKarma=$BadGovernment Edited March 24, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
gcue Posted March 24, 2008 Author Share Posted March 24, 2008 (edited) actually before the dropdown idea i had this: GUICtrlCreateLabel("Enter Asset:", 90, 1) $asset = GUICtrlCreateInput ("", 90, 25, 100, 20) so how can i link that variable $asset with the $arr variable? also, id like to make it possible for the user to enter a new asset if they wanted to.. so that would also be set to $asset MANY MANY thanks! This works with the squirrely.ini listed below it: $moneyGui = GUICreate("Big Bucks", 244, 100) $arr = IniReadSection("squirrely.ini", "ASSETS") If @error Then MsgBox(0,"","Error reading the 'ASSETS' section on line 2") Exit Else GUICtrlCreateCombo($arr[1][0], 10, 10); create combobox and set first item For $i = 2 To $arr[0][0] GUICtrlSetData(-1, $arr[$i][0]); add other items and set a new default control Next EndIf GUISetState() While 1 Sleep(30) $msg = GUIGetMsg() If $msg = -3 Then ExitLoop WEnd squirrely.ini - must be in same directory for the above code to work: [ASSETS] MeAndYourMoney=$MoreThanGod YouAndMyMoney=$CantHappen DoughAndBadKarma=$BadGovernment Edited March 24, 2008 by gcue Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 25, 2008 Share Posted March 25, 2008 (edited) so how can i link that variable $asset with the $arr variable?We can't tell what you mean here - "link?". Or here: also, id like to make it possible for the user to enter a new asset if they wanted to.. so that would also be set to $assetThe variable "$asset" is set to the control-ID of the Input control that your code creates, not to any ini section or key... But if I get what you mean, this works, but the GUI closes right away for some reason using the first Case statement there: #include <GUIConstantsEx.au3> $moneyGui = GUICreate("Big Bucks", 244, 200) $arr = IniReadSection("squirrely.ini", "ASSETS") $combo = GUICtrlCreateCombo($arr[1][0], 10, 10); create combobox and set first item For $i = 2 To $arr[0][0] GUICtrlSetData($combo, $arr[$i][0]); add other items and set a new default control Next GUICtrlCreateLabel("Enter Asset:", 10, 55) $asset = GUICtrlCreateInput("", 10, 75, 100, 20) $buton = GUICtrlCreateButton("Create Section", 10, 110, 110, 31) $dat = "myKey1=myValue1" & @LF & "myKey2=myValue2" & @LF & "myKey2=myValue2" & @LF & "myKey2=myValue2" GUISetState() While 1 Sleep(30) $msg = GUIGetMsg() Switch $msg ;Case $msg = $GUI_EVENT_CLOSE ; ExitLoop Case $buton $newSection = GUICtrlRead($asset) IniWriteSection("squirrely.ini", $newSection, $dat) EndSwitch WEnd In place of IniWriteSection, you could use the function IniWrite after reading up on it in the help file. Edited March 25, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
gcue Posted March 25, 2008 Author Share Posted March 25, 2008 i apologize for not being specific =) here is what im trying to do: i built an app that takes a screenshot of a remote pc. i am a desktop support tech and often need to take screenshots of my users machines, sometimes when i cannot get to them in person. currently the app is working great! but i have to manually enter the PC serialno/asset (thus i figured it would be nice to provide that flexibility by adding the ini for the commonly accessed PCs in addition to manually entering a serialno/asset) i am not trying to add assets via the script. here is a copy of my working script thanks! expandcollapse popupOpt("GUIOnEventMode", 1) #Include <GuiConstants.au3> #Include <Constants.au3> #include <file.au3> Dim $aAuthorizedUsers[11] = ["10","GXM","JJBC","MXK","RACM","FWK","JONE","MALB","KXT","SWT","MONB"] $iAuthorized = 0 For $i = 1 To $aAuthorizedUsers[0] If @UserName = $aAuthorizedUsers[$i] Then $iAuthorized = 1 ExitLoop EndIf Next If Not $iAuthorized Then MsgBox(16,"Access Denied - Invalid Account","You are not authorized to use this application." &@CRLF &@CRLF &"Exiting...",5) Exit(5) EndIf If Not FileExists(@ScriptDir & "\sc.exe") Then MsgBox(16, "Remote Screenshot", "Error: SC.EXE is missing. Application will now exit.") Exit EndIf If Not FileExists(@ScriptDir & "\psexec.exe") Then MsgBox(16, "Remote Screenshot", "Error: PSEXEC.EXE is missing. Application will now exit.") Exit EndIf If Not FileExists("\Screenshots") Then DirCreate("Screenshots") EndIf GUICreate("Remote Screenshot v0.1", 320,80); WS_EX_ACCEPTFILES $helpmenu = GUICtrlCreateMenu ("&Help") $helpitem = GUICtrlCreateMenuitem ("About",$helpmenu) GUICtrlSetOnEvent(-1,"About") GUICtrlCreateLabel("Enter Asset:", 90, 5) $asset = GUICtrlCreateInput ("", 90, 25, 100, 20) $btn = GUICtrlCreateButton ("OK", 205,25,40,20,0x0300) GUICtrlSetOnEvent($btn, "APing") GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton") GUISetState(@SW_SHOW) While 1 Sleep(1000) WEnd Func APing() Ping (GUICtrlRead($asset)) If @error Then MsgBox(16, "Remote Screenshot", GUICtrlRead($asset) & " is offline") Else Call("ARights") EndIf EndFunc Func ARights() RegRead ( "\\" & GUICtrlRead($asset) & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" ) If @error Then MsgBox(16, "Remote Screenshot", "You do not have local admin rights on " & GUICtrlRead($asset)) Else Call("Open") EndIf EndFunc Func Open() If FileExists ("\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") Then FileDelete ( "\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") EndIf FileCopy ("sc.exe", "\\" & GUICtrlRead($asset) & "\c$\temp",1) RunWait(@ScriptDir & "\psexec.exe " & "\\" & GUICtrlRead($asset) & " -d -i c:\temp\sc.exe" ) Sleep(5000) If FileExists ( "\\" & GUICtrlRead($asset) & "\c$\temp\" & "*" & GUICtrlRead($asset) & "*.jpg") Then FileMove("\\" & GUICtrlRead($asset) & "\c$\temp\" & "*" & GUICtrlRead($asset) & "*.jpg", @ScriptDir & "\Screenshots\") Run(@WindowsDir & "\explorer.exe " & @ScriptDir & "\Screenshots") Else MsgBox(16, "Remote Screenshot", 'Unable to take a screenshot from ' & GUICtrlRead($asset) &@CRLF & _ ''&@CRLF & _ 'Probable KNOWN reasons:'&@CRLF & _ ''&@CRLF & _ '1. Asset is on CAD screen.'&@CRLF & _ '2. Bloomberg is the active window.') EndIf Call("Cleanup") EndFunc Func Cleanup() If FileExists ("\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") Then FileDelete ( "\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") EndIf If FileExists ("\\" & GUICtrlRead($asset) & "\c$\temp\noss.flg") Then FileDelete ("\\" & GUICtrlRead($asset) & "\c$\temp\noss.flg") EndIf EndFunc Func About() MsgBox(262144, "About", 'Remote Screenshot v0.1'&@CRLF & _ ''&@CRLF & _ 'Take a screenshot of a remote PC.'&@CRLF & _ ''&@CRLF & _ 'Cannot take remote screenshots when:'&@CRLF & _ ''&@CRLF & _ '1. PC is on the CAD screen.'&@CRLF & _ '2. PC has Bloomberg as the active window.'&@CRLF & _ '3. Tech does not have admin rights on target PC.'&@CRLF & _ '4. Target PC is offline.'&@CRLF & _ ''&@CRLF & _ 'Contact GXM x90760 for questions/suggestions.') EndFunc Func Xbutton() Exit EndFunc Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 25, 2008 Share Posted March 25, 2008 (edited) Okay cgrue, since you seem to have studied my last post, study this slightly altered version, which demonstrates just updating the "ASSETS" section: #include <GUIConstantsEx.au3> $moneyGui = GUICreate("Big Bucks", 244, 200) $arr = IniReadSection("squirrely.ini", "ASSETS") $combo = GUICtrlCreateCombo($arr[1][0], 10, 10); create combobox and set first item For $i = 2 To $arr[0][0] GUICtrlSetData($combo, $arr[$i][0]); add other items and set a new default control Next GUICtrlCreateLabel("Enter Asset:", 10, 55) $newAsset = GUICtrlCreateInput("", 10, 75, 100, 20) $SectionButon = GUICtrlCreateButton("Create Section", 10, 110, 110, 31) GUISetState() While 1 Sleep(30) $msg = GUIGetMsg() Switch $msg ;Case $msg = $GUI_EVENT_CLOSE ; ExitLoop Case $SectionButon $newSection = GUICtrlRead($asset) IniWrite("squirrely.ini", "ASSETS", "serialNo1", "Asset1") IniWrite("squirrely.ini", "ASSETS", "serialNo2", "Asset2") IniWrite("squirrely.ini", "ASSETS", "serialNo3", "Asset3") EndSwitch WEnd This code hasn't been tested, unlike my last post. But it demonstrates use of IniWrite to add-in only new key/value pairs. Edited March 25, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
gcue Posted March 26, 2008 Author Share Posted March 26, 2008 can't get it to read the asset (either entering one, nor pulling from the ini) expandcollapse popupOpt("GUIOnEventMode", 1) #Include <GuiConstants.au3> #Include <Constants.au3> #include <file.au3> Dim $aAuthorizedUsers[11] = ["10","GXM","JJBC","MXK","RACM","FWK","JONE","MALB","KXT","SWT","MONB"] $iAuthorized = 0 For $i = 1 To $aAuthorizedUsers[0] If @UserName = $aAuthorizedUsers[$i] Then $iAuthorized = 1 ExitLoop EndIf Next If Not $iAuthorized Then MsgBox(16,"Access Denied - Invalid Account","You are not authorized to use this application." &@CRLF &@CRLF &"Exiting...",5) Exit(5) EndIf If Not FileExists(@ScriptDir & "\sc.exe") Then MsgBox(16, "Remote Screenshot", "Error: SC.EXE is missing. Application will now exit.") Exit EndIf If Not FileExists(@ScriptDir & "\psexec.exe") Then MsgBox(16, "Remote Screenshot", "Error: PSEXEC.EXE is missing. Application will now exit.") Exit EndIf If Not FileExists(@DesktopDir & "\Screenshots") Then DirCreate(@DesktopDir & "\Screenshots") EndIf If Not FileExists(@ScriptDir & "\assets.ini") Then MsgBox(262144, "Remote Screenshot", "assets.ini is missing. One has been created for you.") IniWrite(@ScriptDir & "\assets.ini", "ASSETS", "Asset_Label1","Asset1") IniWrite(@ScriptDir & "\assets.ini", "ASSETS", "Asset_Label2","Asset2") IniWrite(@ScriptDir & "\assets.ini", "ASSETS", "Asset_Label3","Asset3") ShellExecute(@ScriptDir & "\assets.ini") EndIf GUICreate("Remote Screenshot v0.1", 320,100); WS_EX_ACCEPTFILES $arr = IniReadSection("assets.ini", "ASSETS") $combo = GUICtrlCreateCombo($arr[1][0], 50, 25); create combobox and set first item For $i = 2 To $arr[0][0] GUICtrlSetData($combo, $arr[$i][0]); add other items and set a new default control Next GUICtrlCreateLabel("Enter Asset:", 50, 0) $asset = GUICtrlCreateInput("", 10, 75, 100, 20) $SectionButon = GUICtrlCreateButton("Create Section", 10, 110, 110, 31) $helpmenu = GUICtrlCreateMenu ("&Help") $helpitem = GUICtrlCreateMenuitem ("About",$helpmenu) GUICtrlSetOnEvent(-1,"About") $btn = GUICtrlCreateButton ("OK", 255,27,40,20,0x0300) GUICtrlSetOnEvent($btn, "APing") GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton") GUISetState() While 1 Sleep(30) $msg = GUIGetMsg() Switch $msg ;Case $msg = $GUI_EVENT_CLOSE ; ExitLoop Case $SectionButon $newSection = GUICtrlRead($asset) IniWrite("assets.ini", "ASSETS", "serialNo1", "Asset1") IniWrite("assets.ini", "ASSETS", "serialNo2", "Asset2") IniWrite("assets.ini", "ASSETS", "serialNo3", "Asset3") EndSwitch WEnd Func APing() Ping (GUICtrlRead($asset)) If @error Then MsgBox(16, "Remote Screenshot", GUICtrlRead($asset) & " is offline") Else Call("ARights") EndIf EndFunc Func ARights() RegRead ( "\\" & GUICtrlRead($asset) & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" ) If @error Then MsgBox(16, "Remote Screenshot", "You do not have local admin rights on " & GUICtrlRead($asset)) Else Call("Open") EndIf EndFunc Func Open() If FileExists ("\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") Then FileDelete ( "\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") EndIf FileCopy ("sc.exe", "\\" & GUICtrlRead($asset) & "\c$\temp",1) RunWait(@ScriptDir & "\psexec.exe " & "\\" & GUICtrlRead($asset) & " -d -i c:\temp\sc.exe" ) Sleep(5000) If FileExists ( "\\" & GUICtrlRead($asset) & "\c$\temp\" & "*" & GUICtrlRead($asset) & "*.jpg") Then FileMove("\\" & GUICtrlRead($asset) & "\c$\temp\" & "*" & GUICtrlRead($asset) & "*.jpg", @DesktopDir & "\Screenshots\") Run(@WindowsDir & "\explorer.exe " & @DesktopDir & "\Screenshots") Else MsgBox(16, "Remote Screenshot", 'Unable to take a screenshot from ' & GUICtrlRead($asset) &@CRLF & _ ''&@CRLF & _ 'Probable KNOWN reasons:'&@CRLF & _ ''&@CRLF & _ '1. Asset is on CAD screen.'&@CRLF & _ '2. Bloomberg is the active window.') EndIf Call("Cleanup") EndFunc Func Cleanup() If FileExists ("\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") Then FileDelete ( "\\" & GUICtrlRead($asset) & "\c$\temp\sc.exe") EndIf EndFunc Func About() MsgBox(262144, "About", 'Remote Screenshot v0.1'&@CRLF & _ ''&@CRLF & _ 'Take a screenshot of a remote PC.'&@CRLF & _ ''&@CRLF & _ 'Cannot take remote screenshots when:'&@CRLF & _ ''&@CRLF & _ '1. PC is on the CAD screen.'&@CRLF & _ '2. PC has Bloomberg as the active window.'&@CRLF & _ '3. Tech does not have admin rights on target PC.'&@CRLF & _ '4. Target PC is offline.'&@CRLF & _ ''&@CRLF & _ 'Contact GXM x90760 for questions/suggestions.') EndFunc Func Xbutton() Exit EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now