Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

GUI ComboBox to Triggle Update on Other ComboBox

$
0
0

Was working on a script to let users easily globally add printers from the print servers.

In the past just used a .bat file but decided to wrap it up in AutoIt to make it easier to use and more versitile.

 

I have the code working as is, but I would like to learn something and take it to the next level.

 

I have 2 goals, one is probably easy, the other maybe a bit harder.

 

First goal is instead of having the user manually type the printer name into the inputbox, would it be possible to have the combobox for the server selection populate the 2nd box (would change the inputbox to a combobox) with the list of printer choices.

 

I found good info here: http://www.autoitscript.com/forum/topic/81809-populating-a-combobox-from-an-array-solved/

However I would not be using a static location I would need the first combobox to be chosen and then in real time update the 2nd box based on its value, It would of course need to continue to change in real time incase a selection change is made before they hit the button to exictute the rest of the script.

 

The 2nd goal, once a printer is chosen to add in the 2nd combobox would it be easy enough to display the detailed information about that printer in the GUI so that they can see its location, etc and not only the printershare name.

 

I am not sure how much information can be gathered from a printer before it is added explorer only lets you see Comments, but it would be great if possible to view more than that.

 

Here is the code so far.

 

The GUI

AutoIt         
#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #Include <_NTServices.au3> Global $aArray[2] = ["vprintserv","vprintserv2"] $sList = "" For $i = 0 To UBound($aArray) -1     $sList &= "|" & $aArray[$i]     Next #Region ### START Koda GUI section ### Form=C:\Users\it022565\Desktop\Add Printer GUI\Printer Form.kxf $Form1 = GUICreate("Black Magic Automation", 351, 159, 192, 124) $Combo1 = GUICtrlCreateCombo("print server", 16, 72, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData($Combo1, $sList, "vprintserv2") $Input1 = GUICtrlCreateInput("printer name", 184, 72, 145, 21) $Checkbox1 = GUICtrlCreateCheckbox("Check to Delete", 8, 112, 97, 17) $Button1 = GUICtrlCreateButton("GO!", 242, 111, 75, 25) $Label1 = GUICtrlCreateLabel("Print Server", 56, 48, 59, 17) $Label2 = GUICtrlCreateLabel("Printer", 240, 48, 34, 17) $Label3 = GUICtrlCreateLabel("Add/Delete Global Printer GUI", 24, 8, 281, 28) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $Button1             ExitLoop         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd Local $addel = GUICtrlRead($Checkbox1) Local $printer = GUICtrlRead($Input1) Local $serv = GUICtrlRead($Combo1) If $addel = 1 Then     $addel = "gd" Else     $addel = "ga" EndIf FileInstall("globalprinter.bat", @TempDir & "\globalprinter.bat", 1) _ReplaceStringInFile(@TempDir & "\globalprinter.bat", "$addel$",$addel) _ReplaceStringInFile(@TempDir & "\globalprinter.bat", "$serv$",$serv) _ReplaceStringInFile(@TempDir & "\globalprinter.bat", "$printer$",$printer) ShellExecuteWait(@TempDir & "\globalprinter.bat") sleep(1000) If _ServiceStatus("Spooler") <> "Stopped" Then _ServiceStop("Spooler") While 1     Sleep(200)     If _ServiceStatus("Spooler") = "Stopped" Then ExitLoop WEnd _ServiceStart("Spooler")

The .bat file I am executing

cd /d "%~dp0" rundll32 printui.dll PrintUIEntry /$addel$ /n"\\$serv$\$printer$"

** Yes I know I am strange running a .bat intead of using @ComSpec its just a preference for me though in this case @ComSpec should have been easy enough. 


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>