Jump to content

listing files


Recommended Posts

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.

#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
Link to comment
Share on other sites

  • Moderators

anybody know how to solve this? or even have a hint? :D

Not even sure if there was a direct question there volly... and I see your still making "long" scripted GUI's with arrays :P:D

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

I think this is what your looking for you'll just have to adapt it to a combo box

Opt("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

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)

NEWHeader1.png

Link to comment
Share on other sites

  • 4 weeks later...

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

Edit2: 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 by vollyman
Link to comment
Share on other sites

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

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 by vollyman
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...