Answers:
在Windows XP中,使用prntmngr:
PRNMNGR -l >> C:\printers.txt
在Windows Vista及更高版本中,使用PowerShell:
get-WmiObject -class Win32_printer | ft name, systemName, shareName >> c:\printers.txt
注意:如果您尝试将文件写入Vista +上的C:\,则可能会出错,具体取决于您的权限以及生成PowerShell的方式。
对于Windows 2000:
XP中的PrnMngr.vbs文件(位于/ Windows / System32文件夹中)在Windows 2000上可以使用。只需从XP计算机中找到并将其复制到2000计算机上,然后使用以下命令运行它:
cscript prnmngr.vbs -l >> c:\printers.txt
我发现由于某种原因它无法从用户的桌面运行,但是当我将.VBS复制到C的根目录时:它运行良好。
我用:
wmic printer list brief
要么
wmic printer get name
这只是显示连接到运行命令的系统的打印机的简短列表。如果有网络打印机,还将显示打印机连接到的计算机。
您还可以使用它来获取系统上安装的每台打印机的非常详细的配置列表:
wmic printer list full
要将其输出到文本文件,请将其附加到命令末尾:
>>"[directory]\[filename].txt"
例:
wmic printer list brief >> c:\users\admin\documents\printerlist.txt
从Windows 8 / Server 2012开始,有一个get-printer
PowerShell cmdlet:
https://technet.microsoft.com/zh-cn/library/hh918358%28v=wps.630%29.aspx?f=255&MSPPError=-2147217396
所以这是我的解决方案:
;******************
;ALLOCATING CONSOLE
;******************
; cmd calls hidden
global cPid
DetectHiddenWindows, on
Run, %comspec% /k ,,Hide UseErrorLevel,cPid
WinWait, ahk_pid %cPid%,, 1
DllCall("AttachConsole","uint",cPid)
hCon:=DllCall("CreateFile","str","CONOUT$","uint",0xC0000000,"uint",7,"uint",0,"uint",3,"uint",0,"uint",0)
;******* GET PRINTER NAMES **********
AllPrintersNameClearArray := strSplit(StrReplace(StrReplace(StrReplace(StrReplace("|" StrReplace(StrReplace(StrReplace(RunWaitOne("wmic printer get name")," ","")," `r",""),"`r",""),"|NAME`n",""),"`n","|"),"||","",All),"|","`n"),"`n")
RunWaitOne(command) {
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(command)
strStdOut := ""
while, !objExec.StdOut.AtEndOfStream
strStdOut := objExec.StdOut.ReadAll()
return %strStdOut%
}
; **** Clean at the end *****
Finish:
DllCall("CloseHandle", "uint", hCon)
DllCall("FreeConsole")
Process, Close, %cPid%
ExitApp
return