windows 从命令行获取默认打印机名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13311201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:03:11  来源:igfitidea点击:

Get default printer name from command line?

windowswindows-7

提问by Kimi

Microsoft Windows XP comes with a VBS script to manage local and network printers from the command line:

Microsoft Windows XP 附带了一个 VBS 脚本,用于从命令行管理本地和网络打印机:

To Get the default printer details from command line:

从命令行获取默认打印机详细信息:

cscript C:\windows\system32\prnmngr.vbs -g

To Get the list of printers added to the system from Windows command line:

从 Windows 命令行获取添加到系统的打印机列表:

cscript C:\windows\system32\prnmngr.vbs -l

Is there any equivalent commands for Windows 7? I just need to get the default printer details and get the list of printers attached to the system.

是否有适用于 Windows 7 的等效命令?我只需要获取默认打印机详细信息并获取连接到系统的打印机列表。

回答by Bali C

In Windows 7 these same scripts are found in

在 Windows 7 中,这些相同的脚本位于

C:\Windows\System32\Printing_Admin_Scripts\en-US

回答by Maciej Pulikowski

List of all printers names and shows default one (You can get more details read documentation)

列出所有打印机名称并显示默认名称(您可以阅读文档获取更多详细信息)

wmic printer get name,default

If you want output to file use:

如果你想输出到文件使用:

wmic printer get name,default > D:\catalog\file.txt

Availability

可用性

The wmic command is an external command that is available in the below Microsoft operating systems as wmic.exe.

wmic 命令是在以下 Microsoft 操作系统中可用的外部命令 wmic.exe。

Windows XP professional
Windows 2003
Windows Vista
Windows 7
Windows 8
Windows 10

回答by Rich701

i found mine in the sideXside folder...

我在 sideXside 文件夹中找到了我的...

C:\windows\winsxs\x86_microsoft-windows-p..inscripts.resources_31bf3856ad364e35_6.1.7600.16385_en-us_0e83b619ada3e7ed\

C:\windows\winsxs\x86_microsoft-windows-p..inscripts.resources_31bf3856ad364e35_6.1.7600.16385_en-us_0e83b619ada3e7ed\

i ran the following: cscript C:\windows\winsxs\x86_microsoft-windows-p..inscripts.resources_31bf3856ad364e35_6.1.7600.16385_en-us_0e83b619ada3e7ed\prnmngr.vbs -g

我运行了以下命令:cscript C:\windows\winsxs\x86_microsoft-windows-p..inscripts.resources_31bf3856ad364e35_6.1.7600.16385_en-us_0e83b619ada3e7ed\prnmngr.vbs -g

it worked.

有效。

回答by codesniper

To list active printer components on Windows 8.1:

要列出 Windows 8.1 上的活动打印机组件:

c:>cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l | findstr "Printer name"

c:>cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l | findstr "打印机名称"

enter image description here

在此处输入图片说明

回答by Cefoussa

On Windows 10, the scripts are found in the same place as Windows 7. Execute the following command to display the default printer.

在 Windows 10 上,脚本与 Windows 7 位于同一位置。执行以下命令以显示默认打印机。

cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -g

Note if there is no default printer, the script will return nothing

注意如果没有默认打印机,脚本将不返回任何内容

回答by Lloyd Medley

To remove printer in Windows 8.1:

在 Windows 8.1 中删除打印机:

cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Printer name"

I had trouble with a printer not showing in devices/printers so unable to remove it, although it was there when I pressed file > print in firefox. It was also stopping me from using the printer name for the actual installation (it bugged me having to append _1 at the end of the default printer!"

我在设备/打印机中没有显示打印机时遇到了问题,因此无法将其删除,尽管当我在 firefox 中按下文件 > 打印时它就在那里。它还阻止我在实际安装中使用打印机名称(这让我不得不在默认打印机的末尾附加 _1!”

回答by Anic17

Using a batch file (no VBS):

使用批处理文件(无 VBS):

@echo off

::Get printer CLSID
for /f %%a in ('reg query HKCU\Printers\Defaults') do (set regkey=%%a)
::Get printer name from the previous CLSID

for /f "tokens=3*" %%a in ('reg query %regkey%') do (set printername=%%a %%b)
echo Printer name is: %printername%

I wish that could help you

我希望这可以帮助你