We help IT Professionals succeed at work.

Print from Default Printer using Windows Batch script

Print from Default Printer using Windows Batch script

I have a list of computers in CSV File. I would like to have a script that reads each computer from the file and connect to its default printer and send a test page to printer ,for instance "PrinterA" that 's the port/host name.
 
so the print test  job will come out with the computer name and the printer it printed from.

Thank you
Comment
Watch Question

Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
Can I ask why? Is it just to get a list of the printers people use? That is user based dont forget so it depends who is logged in at the time, also Windows 10 handles the default printer used in its own way.

Author

Commented:
just to make sure the remote computer is able to the printer I chose as default printer.
I know that if logged on user choose another default printer it will be different from the one I chose.
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
OK the only realistic way I think would be to record a user's default printer on that computer using a script they run when they are logged on, e.g. from a login script or group policy.  There are various ways including as simple as:

cscript //nologo C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -g > \\server\share\printers\default-%computername%-%username%.txt
cscript //nologo C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l > \\server\share\printers\list-%computername%-%username%.txt

that would create a file for each computer and user combination saying what the default printer is and list of all the printers and their connection details.

There are some suggestions here for how to do it with powershell to get the current logged in user and get their default printer

https://stackoverflow.com/questions/20639541/get-default-printer-remotely

Author

Commented:
can you tell me what these scripts do ?
Thank you

cscript //nologo C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -g > \\server\share\printers\default-%computername%-%username%.txt
cscript //nologo C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l > \\server\share\printers\list-%computername%-%username%.txt

Open in new window

IT Consultancy
CERTIFIED EXPERT
Commented:
Sure. When run as a user on a PC they write a list of all printers and the default printer into a text file based on the computer name and username.

Try them without the > and filename and you will see.

If you run them from an existing login script day and change the filename to point at a share that all users can write to or a drive letter already mapped by that point then it will maker two text files each telling you the default printer name and list of all the printers.

If you particularly want we could trigger a page to print to the printer with some basic details on.

Steve

Author

Commented:
Steve Knight


Thank you for your help.

I guess  you took some steps farther than what I asked. I appreciate that.
I want just with one account (local administrator) in each computer i have listed on the CSV file, to print from a default printer .
Default from the perspective of administrator account  as I know the default can change from one user to another who logged in to the computer.
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
I am not sure how best to do that, sorry or see the value in it unless the administrator account is logged into and running a job.

Steve

Author

Commented:
yes the Administrator account is running the script and accessing the remote computer via script and printing from default printer

Author

Commented:
Thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.