landfish 发表于 2013-3-3 19:58:57

AU3 删除本地打印机

本帖最后由 landfish 于 2013-3-4 15:12 编辑

以下脚本是AU3 US找来的,但是编译之后运行失败哪位高人帮忙看下。。。谢谢


$strComputer = "."
Global $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
Global Chr = $objWMIService.ExecQuery _
        ("Select * From Win32_Printer Where Network = false")
For $objPrinter in $colInstalledPrinters
        $objPrinter.Delete_
Next

这段源码是从AU3美国网站找来的,以下链接可能要翻墙访问
http://www.autoitscript.com/forum/topic/141656-convert-vbs-that-utilizes-wmi-into-an-autoit-script/page__hl__+vbs%20+convert#entry996550

Guys, I have used AutoIT for a long time now, although I have the task of either A. executing the .vbs script with an AutoIT application, or taking the code out of the .vbs and placing it into the actual AutoIT application. Luckly, everything the .vbs does is done within WMI. It queries all the networked printers then deletes them from the machine. Not local printers, but network printers. Here is the .vbs code. How can I script this code to execute within the AutoIT application instead of launching the .vbs file?

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
        ("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
        objPrinter.Delete_
Next
·········
Luckily VBScript and AutoIt are very similar, there's very little conversion required.

[ autoit ]      popup
$strComputer = "."
Global $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
Global $colInstalledPrinters = $objWMIService.ExecQuery _
    ("Select * From Win32_Printer Where Network = True")
For $objPrinter in $colInstalledPrinters
    $objPrinter.Delete_
Next

kevinch 发表于 2013-3-3 21:08:56

Where Network = fales
应该是false吧

还有delete后面的下划线是干嘛的

landfish 发表于 2013-3-3 21:42:00

delete_谷歌了一下,虽然不知道下划线用途但是很多代码都这么写

link369 发表于 2013-3-3 22:22:22

学习学习。。。。。搞不懂

wsfda 发表于 2013-3-4 08:26:11

我感觉好像是语法上的错误,但是具体哪里不清楚

weeks1 发表于 2013-3-4 08:42:49

学习学习。。。。。

landfish 发表于 2013-3-5 17:01:18

等高人作答~~

872777825 发表于 2013-3-5 19:29:01

有点复杂 看得不是很明白
页: [1]
查看完整版本: AU3 删除本地打印机