Avatar of jskfan
jskfan
Flag for Cyprus asked on

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
Windows BatchScripting Languages

Avatar of undefined
Last Comment
jskfan

8/22/2022 - Mon
Steve Knight

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.
jskfan

ASKER
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 Knight

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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
jskfan

ASKER
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

ASKER CERTIFIED SOLUTION
Steve Knight

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jskfan

ASKER
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 Knight

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jskfan

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

ASKER
Thanks