找回密码
 加入
搜索
查看: 4414|回复: 7

[网络通信] 求助EnumPrinters在AUTOIT调用方法

  [复制链接]
发表于 2014-12-2 16:32:49 | 显示全部楼层 |阅读模式
想检索出局域网内共享打印机,看到可以使用这个API,但试了好久不知如何使用,求高手指点!
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162692(v=vs.85).aspx

DllCall("dll","BOOL","EnumPrinters","DWORD",Flags,"str",Name,"DWORD",Level,"BYTE*",pPrinterEnum,"DWORD",cbBuf,"DWORD*",pcbNeeded,"DWORD*",pcReturned)
发表于 2014-12-3 08:18:37 | 显示全部楼层
[au3]Func _ENumPrinters($flags = $PRINTER_ENUM_LOCAL)
    Local $plist

;stop illegal flags
    $flags = BitAND($flags, BitOR($PRINTER_ENUM_CONNECTIONS, $PRINTER_ENUM_LOCAL))
    If $flags = 0 Then Return SetError(1, 1, '')
   
    Local $Name = ''
    Local $level = 4;uses gets printer_Info_4 which uses registry. Could be done with Printer_Info_2 but can cause long delay
                   ; if printer no longer installed or remote PC not available.   
     
    Local $cbBuf = 0;no space allowed but we will be told how much is needed
    Local $struct_enum = DllStructCreate("char[" & $cbBuf & "]")
    Local $pPrinterEnum = DllStructGetPtr($struct_enum)

    Local $pcbNeeded, $pcReturned, $n, $printerdesc, $thisPrinter
    $ret = DllCall("winspool.drv", "int", "EnumPrinters", "dword", $flags, "str", $Name, "dword", $level, "ptr", $pPrinterEnum, _
            "dword", $cbBuf, "dword*", $pcbNeeded, "dword*", $pcReturned)
    If @error Then Return SetError(1, 1, "")
   
    If $ret[6] > $ret[5] Then; if we need more space than we allowed
        $struct_enum = DllStructCreate("char[" & $ret[6] & "]")
        $pPrinterEnum = DllStructGetPtr($struct_enum)
        $ret = DllCall("winspool.drv", "int", "EnumPrinters", "dword", $flags, "str", $Name, "dword", $level, "ptr", $pPrinterEnum, _
                "dword", $ret[6], "dword*", $pcbNeeded, "dword*", $pcReturned)
        If @error Then Return SetError(2, 2, "")
    EndIf
   
    For $n = 0 To $ret[7] - 1;for each $PRINTER_INFO_4 structure in the array of $PRINTER_INFO_4's returned
        $ans = DllStructCreate($PRINTER_INFO_4, $pPrinterEnum + $n *12)
        
        $n1 = DllStructCreate("char[256]", DllStructGetData($ans, 1));2 for info_1
        
        $printerdesc = DllStructGetData($n1, 1)
        
        If StringInStr($printerdesc, ',') Then
            $thisPrinter = StringLeft($printerdesc, StringInStr($printerdesc, ',') - 1)
        Else
            $thisPrinter = $printerdesc
        EndIf
        
        If $thisPrinter <> '' Then $plist &= $thisPrinter & '|'
        
    Next
   
    If $plist = "" Then Return $plist
   
    Return StringLeft($plist, StringLen($plist) - 1)
EndFunc  ;==>_ENumPrinters[/au3]
 楼主| 发表于 2014-12-3 08:29:32 | 显示全部楼层
回复 2# netegg


   先谢谢了!我去试试
发表于 2014-12-3 08:32:21 | 显示全部楼层
怎么这几天到处都有蛋神存在.....
 楼主| 发表于 2014-12-3 08:40:03 | 显示全部楼层
回复 2# netegg


   看了一遍,有点云里雾里,有没有一个实际应用,谢谢了~
发表于 2014-12-3 10:54:28 | 显示全部楼层
回复 4# austere

闲的没事,瞎溜达
发表于 2014-12-5 08:39:02 | 显示全部楼层
前来学习。。。。。。。。。。。。。。
发表于 2021-3-24 12:18:35 | 显示全部楼层
求助,想实现遍历局域网的共享打印机,没看懂,求大神指点
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 03:00 , Processed in 0.124996 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表