Bert Posted June 14, 2006 Share Posted June 14, 2006 Simple question: I have a combo box. I want to list all my printer shares from a server. I looked in the helpfile, but I couldn't find what I wanted. Does anyone have a example I can look at so I can get a idea on how to do it? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted June 14, 2006 Author Share Posted June 14, 2006 (edited) What I'm looking to do is get a list of printer shares on a NT print server and put them in a combo box so one can select what they want to use. Thoughts? Edited June 14, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted June 14, 2006 Author Share Posted June 14, 2006 This is the script I'm attempting to build. Basically it will allow for someone to install network printers on a machine basis instead of a profile basis. It will have the ability to remove attached printers, and have a exclude list so ones you do not want to have removed will stay put. It will also save settings so you can run this from the network by putting it in your logon script. This will allow for someone to easily add or change printers. If I could just solve the problem where one types in a server name, and the printer shares could be posted into the combo boxes, that would be great. expandcollapse popup#include <GuiConstants.au3> GuiCreate("", 392, 260,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_1 = GuiCtrlCreateInput("Print Server name", 20, 50, 163, 20) $Combo_2 = GuiCtrlCreateCombo("1st network printer", 200, 50, 170, 21) $Combo_3 = GuiCtrlCreateCombo("2nd network printer", 200, 75, 170, 21) $Combo_4 = GuiCtrlCreateCombo("3rd", 200, 100, 170, 21) $Combo_5 = GuiCtrlCreateCombo("4th", 200, 125, 170, 21) $Combo_6 = GuiCtrlCreateCombo("5th", 200, 150, 170, 21) $Combo_7 = GuiCtrlCreateCombo("Exclude List", 200, 200, 170, 21) $Radio_8 = GuiCtrlCreateRadio("Default", 23, 120, 70, 15) $Radio_9 = GuiCtrlCreateRadio("Change all", 23, 140, 70, 15) $Radio_10 = GuiCtrlCreateRadio("Install only", 23, 160, 70, 15) $Button_11 = GuiCtrlCreateButton("Run", 20, 190, 80, 30) $Button_12 = GuiCtrlCreateButton("Exit", 110, 190, 73, 30) $button_13 = GuiCtrlCreateButton("Add Exclude", 110, 150, 73, 30) $button_14 = GuiCtrlCreateButton("Save Settings", 110, 110, 73, 30) $Label_15 = GuiCtrlCreateLabel("Network Printer Utility 1.0", 20, 10, 340, 35) $font="Comic Sans MS" $checkbox_16 = GUICtrlCreateCheckbox("Use saved settings", 20, 72, 120, 20) $checkbox_17 = GUICtrlCreateCheckbox("Autorun", 20, 92, 70, 20) GUICtrlSetFont($Label_15, 14, 400, "", $font) GUICtrlCreateGroup("", 20, 110, 80, 70) $menu_18 = GUICtrlCreateMenu("&File") $menu_19 = GUICtrlCreateMenuitem("&Run", $menu_18) $menu_20 = GUICtrlCreateMenuitem("&View Exclude list", $menu_18) $menu_21 = GUICtrlCreateMenuitem("&Add to Exclude list", $menu_18) GUICtrlCreateMenuitem("", $menu_18) $menu_22 = GUICtrlCreateMenuitem("&Use saved settings", $menu_18) $menu_23 = GUICtrlCreateMenuitem("&Autorun", $menu_18) $menu_24 = GUICtrlCreateMenu("&Help") $menu_25 = GUICtrlCreateMenuitem("&How to use NPU", $menu_30,1) $menu_26 = GUICtrlCreateMenuitem("A&bout NPU", $menu_30,1) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $menu_22 If BitAnd(GUICtrlRead($menu_22),$GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($menu_22,$GUI_UNCHECKED) Else GUICtrlSetState($menu_22,$GUI_CHECKED) EndIf Case $msg = $menu_23 If BitAnd(GUICtrlRead($menu_23),$GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($menu_23,$GUI_UNCHECKED) Else GUICtrlSetState($menu_23,$GUI_CHECKED) EndIf Case Else ;;; EndSelect WEnd Exit The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted June 15, 2006 Author Share Posted June 15, 2006 anybody know how to solve this? or even have a hint? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 15, 2006 Moderators Share Posted June 15, 2006 anybody know how to solve this? or even have a hint? Not even sure if there was a direct question there volly... and I see your still making "long" scripted GUI's with arrays 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 More sharing options...
Bert Posted June 15, 2006 Author Share Posted June 15, 2006 (edited) I want to do a directory listing of any printer shares on a print server, then post that list into a combo box. edit: the script was made with the gui builder, with a small amount of tweaking.... Edited June 15, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
GaryFrost Posted June 15, 2006 Share Posted June 15, 2006 I think this is what your looking for you'll just have to adapt it to a combo box expandcollapse popupOpt("MustDeclareVars", 1) _Main() Func _Main() Local $a_sh_printers = _PrinterShares(@ComputerName) If Not @error And IsArray($a_sh_printers) Then For $i = 1 To $a_sh_printers[0] MsgBox(0, @ComputerName & ' Shared Printers', $a_sh_printers[$i]) Next EndIf EndFunc ;==>_Main Func _PrinterShares($strComputer) Local Const $wbemFlagReturnImmediately = 0x10 Local Const $wbemFlagForwardOnly = 0x20 Local $colItems = "", $objItem, $objWMIService, $a_printers $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Share WHERE Type = 1 OR Type = 2147483649", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If IsArray($a_printers) Then ReDim $a_printers[UBound($a_printers) + 1] Else Dim $a_printers[2] EndIf $a_printers[0] = UBound($a_printers) - 1 $a_printers[UBound($a_printers) - 1] = $objItem.Name Next Return $a_printers Else SetError(1) Return 0 EndIf EndFunc ;==>_PrinterShares SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Valuater Posted June 15, 2006 Share Posted June 15, 2006 just as i was about to help Local $hService, $sPrinter, $sPrinterList $hService = ObjGet ("winmgmts:{impersonationLevel=impersonate}!" & "\\" & @ComputerName & "\root\cimv2") If Not @error = 0 Then Exit EndIf $sPrinterList = $hService.ExecQuery ("Select * From Win32_Printer") For $sPrinter In $sPrinterList MsgBox(64, "Printer", $sPrinter.name) ; guictrlsetdata($combo, the info above......) Next 8) Link to comment Share on other sites More sharing options...
Bert Posted June 15, 2006 Author Share Posted June 15, 2006 Thanks guys. I was about to do this in WinBatch, but making GUIs are somewhat more tricky with that language. I wonder if some printer functions could be added to a future beta.... The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted June 16, 2006 Author Share Posted June 16, 2006 Val's code works great on a NT server. What do you do to get the printers listed on a Novell server? I have no idea on this one. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Valuater Posted June 16, 2006 Share Posted June 16, 2006 Val's code works great on a NT server. What do you do to get the printers listed on a Novell server? I have no idea on this one.whats Novell... is that like a Christmas song... lolI have no idea.. did you try gafrosts code??8) Link to comment Share on other sites More sharing options...
Bert Posted June 16, 2006 Author Share Posted June 16, 2006 I haven't tried his yet, for yours was basically one line, and for the server I was looking to connect to , it worked well. When my coworker asked me how to connect to a novell server.... was I. I'll try Gary's code to see how it works. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted July 13, 2006 Author Share Posted July 13, 2006 (edited) I tried using Gary's code. It will work fine on a Windows server, but bombs on line 22 if I try it on a Novell server. C:\Documents and Settings\a4mh3\Desktop\autoit scrips\printer tool\printerseektest.au3 (22) : ==> Variable must be of type "Object".: $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Share WHERE Type = 1 OR Type = 2147483649", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colItems = $objWMIService^ ERRORI see the the command ExecQuery. What is that and how does it work?Edit: I answered my question on ExecQuery: http://msdn.microsoft.com/library/default....s_execquery.aspEdit2: It looks like this is what I need to do to fix the problem, but is is quite confusing. Can anyone lend some guidance on how to query a novel server for printers? Edited July 13, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
GaryFrost Posted July 13, 2006 Share Posted July 13, 2006 I tried using Gary's code. It will work fine on a Windows server, but bombs on line 22 if I try it on a Novell server. C:\Documents and Settings\a4mh3\Desktop\autoit scrips\printer tool\printerseektest.au3 (22) : ==> Variable must be of type "Object".: $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Share WHERE Type = 1 OR Type = 2147483649", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colItems = $objWMIService^ ERROR I see the the command ExecQuery. What is that and how does it work? Edit: I answered my question on ExecQuery: http://msdn.microsoft.com/library/default....s_execquery.asp Haven't used Novell since about 1989, so I don't know what it supports but WMI stands for Windows Management Instrumentation. From what I remember back when I used Novell it didn't support WMI. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Bert Posted July 13, 2006 Author Share Posted July 13, 2006 (edited) Ok, makes sense. I'm being directed to see if I can make my printer utility work with Novell servers as well as Windows servers. My thinking is if it is ran on a Novell server, I can use the HP Universal print driver for we are a HP shop. Just getting the list of Novell printers is the sticky point. Edited July 13, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted July 13, 2006 Author Share Posted July 13, 2006 Everything I'm finding tells me how to finds things out about the printer queues, but not how to get a list of them. The Vollatran project My blog: http://www.vollysinterestingshit.com/ 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