none
Set default printer via scheduled task/batch file not working RRS feed

  • Question

  • We are running virtual machines via Windows Multipoint Server and have spun up a new one, trying to resolve some issues. The printers are installed on the Hyper-V machine and I assign printers for each user (group policy created a printer nightmare, hence the reason for the new wms).

    I've written a batch file that works with the administrator logged in & the rdp session open. It's been simplified down to just 2 lines that I'm having issues with:

    rem default printer

    cscript %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -g >> "c:\Users\vradmin\Documents\SchedBatch\Results.log"

    rem change default printer

    cscript %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p \\VRSERVER\Printer020 >> "c:\Users\vradmin\Documents\SchedBatch\Results.log"

    All I'm trying to do is find out what the current default printer is & change it to Printer020.

    From Task Scheduler, I have a task built to run only when the user is logged on and with the highest privileges. Works just fine, as long as the .rdp to the wms stays open. If I schedule the task and close the .rdp (not logging off, just closing), it will write the default to the log, but will not change it to Printer020.

    I've searched all over the internet and cannot find any similar issues. Any help or direction would be greatly appreciated!

    Thanks!

    Thursday, May 15, 2014 5:14 PM

Answers

  • If you are using only the runtime then you will need to have the access module set its own printer by name.

    If you post your issue in the MSAccess developer forum they might have links to KBs and other resources explaining how to best manage printers. 

    I have built dozens of MSAccess apps over the years.  Selecting printers is tricky in MSAccess.  I have not done pronter selection in Access since 2007 version so check with the VBA developers.


    ¯\_(ツ)_/¯

    Monday, May 19, 2014 5:28 PM

All replies

  • What Hyper-V machine.  Is it XP? Vista? WS2012?  What are you trying to say.

    We do npot it use those scritps to assign printers.  They are for workgroup and for old systems and are available for compatibility only.

    Are your servers in a domain?  If so use Group Policy. You may have issues if you do not know how to use Group Policy.  Get someone to work with you to set it up.  It is extremely easy but is dependent on you deployment.

    If I knew more about your setup I would post a GP that is set to attach and set a printer as the default. All you need to do is import it and change the printer name and you are set.

    Search for instructions on using GP to assign printers.  There are a very large number of videos and blogs discussing how to do it.


    ¯\_(ツ)_/¯

    Thursday, May 15, 2014 5:30 PM
  • We are running virtual machines via Windows Multipoint Server and have spun up a new one, trying to resolve some issues. The printers are installed on the Hyper-V machine and I assign printers for each

    All I'm trying to do is find out what the current default printer is & change it to Printer020.

    From Task Scheduler, I have a task built to run only when the user is logged on and with the highest privileges. Works just fine, as long as the .rdp to the wms stays open. If I schedule the task and close the .rdp (not logging off, just closing), it will write the default to the log, but will not change it to Printer020.

    You can also find many simple scripts in the repository that will change a printer. No need to use task scheduler - just use a logon script.


    ¯\_(ツ)_/¯

    Thursday, May 15, 2014 5:33 PM
  • This will always get you the default printer.

    wmic printer where "default=True" get name


    ¯\_(ツ)_/¯

    Thursday, May 15, 2014 5:42 PM
  • Thanks for the suggestions, however, I may have simplified the problem too much.

    I want to change the printer from the default to another, open & run MSAccess vba, print a report, and change it back to the default. I've tried numerous ways to do this, including just setting the printer on the report design within MSAccess. That did not work.

    My network guys told me to do it in the batch file before opening MSAccess. That's where I noticed it was not working in the script. Or more specifically, it works when the rdp session is open, but not closed with the administrator still logged in.

    I simplified the script down to just changing the printer from the default to the other one (printer020), and scheduled it so it will run when I did not have the rdp open.

    Any ideas why it won't change?

    Thanks,

    Connie

    Monday, May 19, 2014 10:56 AM
  • Office products set their own default on a per document basis.  Post your issue in the Office forum.

    Running system utilities under the scheduler is not a scripting issue.  It is an issue with how to use Windows components and utilities.

    Office products will not run as expected under the task scheduler.  This is well documented by Microsoft.  Office will not be run with no UI. If it is run it will not run reliably.


    ¯\_(ツ)_/¯

    Monday, May 19, 2014 2:12 PM
  • jrv, thanks for your reply. I've never had any issues running MSaccess macros through the task scheduler (other than this). The report itself is set to print to the default printer, whatever that may be. And it does if I run it logged in as different users. But I need to print periodically.

    I am unclear on what you mean by 'system utilities'. I have not found anything indicating the script itself is incorrect; but I am unsure of what the problem could possibly be. I was hoping someone has had this happen & had a solution.

    Monday, May 19, 2014 4:50 PM
  • The script you are running is a system utility script.  Your question is about how to use a utility script to do something it was never intended to do.  It doesn't work as you can see.

    Microsoft Office Products cannot be relied on to work when there is no UI.  If you have issues with either of these items it is not a script issue.

    Why not set your access report to use a specific printer.  Why ask it to use only the default printer.

    There are technical issues that happen when you try to do what you are trying to do.  It has to do with async nature of Windows and with other issues.

    You can try other methods and test things until you figure out a solutions.  Why not use VBScript or pass a printer name to Access on the command line and have a macro in access change printers. 

    In the end I don't see how we can be of much help.  Whether the utility works or it doesn't is not a scripting issue.  If you place a call to MS support they will tell you pretty much what I have told you.  MSAccess is not supported under your configuration.  The scripts are not supported under your configuration. You have already seen that this works when you are logged in but not when you are not. That should be a clue that I am right.

    Maybe someone else will have some ideas but I doubt you will get this going without using a macro.


    ¯\_(ツ)_/¯

    Monday, May 19, 2014 5:14 PM
  • I should also note that when you choose the default printer in a report it will likely capture the printer name and remember that.  Use a VBA script to print out the name of the selected printer in the report object.  I think you will find that I am correct.

    If you use MSAccess to set the printer for the report perhaps you will get around this issue.


    ¯\_(ツ)_/¯

    Monday, May 19, 2014 5:18 PM
  • I originally tried to design the report with that printer specifically, however it did not work, and the suggestion from my network administrator was to use the batch file to change it & then change it back. I have MS Access installed on my Windows 7 desktop, however only have MSAccess runtime on the wms, where it's actually scheduled. My guess was that there were differences between the 2 systems and that's why it would not work.

    Monday, May 19, 2014 5:21 PM
  • If you are using only the runtime then you will need to have the access module set its own printer by name.

    If you post your issue in the MSAccess developer forum they might have links to KBs and other resources explaining how to best manage printers. 

    I have built dozens of MSAccess apps over the years.  Selecting printers is tricky in MSAccess.  I have not done pronter selection in Access since 2007 version so check with the VBA developers.


    ¯\_(ツ)_/¯

    Monday, May 19, 2014 5:28 PM
  • Thanks jrv. I'll give it a try.
    Monday, May 19, 2014 5:29 PM
  • Just as an aside, changing a user's default printer because of a specific application is sometimes called "using a global state to manage a local problem." Changing the default printer affects all programs the user runs and is thus generally not the correct solution to the problem in the first place.


    -- Bill Stewart [Bill_Stewart]

    Monday, May 19, 2014 6:00 PM
    Moderator