プリンターの一覧をGUI経由で取得する時、いちいち書き記さないといけないが、コマンドプロンプト/PowerShellから一覧を取得できればそのままテキストに出力できるので楽です。
目次
コマンドプロンプトからの場合
コマンドプロンプトからは基本的にcscript経由でvbsを呼び出す形になります。
Windows XP以降
cscript c:\windows\system32\prnmngr.vbs -l
Windows Vista/7/8/10/Server 2008 SP2/Server 2008 R2 以降
cscript C:\Windows\System32\Printing_Admin_Scripts\ja-JP\prnmngr.vbs -l
もしくは
wmic printer get name
wmic printer list brief
wmic printer list full
出力例

Windows XPにてプリンターのリストを出力。一回目は、インストールされているプリンターは無し、2回目はプリンターをインストールして出力、3回目は先ほどのプリンターをGUIから削除してから再度プリンターのリストを出力。
補足
Windows Vista以降でcscriptにて今回のVBSを使う場合、PATHにC:\Windows\System32\Printing_Admin_Scripts\ja-JP\
を登録しておくか、Full Pathを上記例の通り記述して実行するかになります。
なお、C:\Windows\System32\Printing_Admin_Scripts\ja-JP\
のja-JPはインストールされているWindowsの言語により変わるので英語バージョンのWindowsならen-USと置き換えます。
C:\Windows\System32\Printing_Admin_Scripts\en-US\
PowerShellからの場合
Windows Vista/7/8/10/Server 2008 SP2/Server 2008 R2 以降
get-WmiObject -class Win32_printer
get-WmiObject -class Win32_printer | ft name, shareName
コメント