# system.print.getDefaultPrinterName() returns null

**URL:** <https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803>\
**Category:** Ignition\
**Created:** [January 4, 2024, 5:34pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803 "2024-01-04T17:34:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [January 4, 2024, 5:34pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/1 "2024-01-04T17:34:46Z")

</div>

I have a gateway where we need to print labels and reports. We are able to do so if we run system.print.getPrinterNames() and print to one of the returned values but would prefer to print to the default printer (at least for the reports). When we run system.print.getDefaultPrinter(), the returned value is null. If I RDP into the gateway box, I can confirm that a default printer is set up on the box. I can even change the default to the Microsoft PDF driver and the returned value is still null.  
Anyone have any ideas what we're missing?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 4, 2024, 5:37pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/2 "2024-01-04T17:37:15Z")

</div>

I'm assuming Windows...

Generally, the user that is running the Ignition service doesn't have enough permissions to obtain that information.

You will need to change the service user to a user that has the proper permission and then restart the Ignition service.

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [January 4, 2024, 5:39pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/3 "2024-01-04T17:39:27Z")

</div>

Yes, Windows Server 2019 is the OS. We have already setup up the user and the Ignition service is configured to use that user. Printing works and we can get the printer names from system.print.getPrinterNames(). It's only the default printer we cannot retrieve.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 4, 2024, 5:41pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/4 "2024-01-04T17:41:35Z")

</div>

How/where are you running each `system.print` function?

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [January 4, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/5 "2024-01-04T17:46:16Z")

</div>

We are running the code on a button event on a Perspective view.

This works:

```
printers = system.print.getPrinterNames()[0]
self.view.custom.defaultPrinter = printers 

```

This returns null:

```
defaultPrinter = system.print.getDefaultPrinter()
self.view.custom.defaultPrinter = defaultPrinter

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 4, 2024, 5:56pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/6 "2024-01-04T17:56:37Z")

</div>

There's a bunch of possible failure cases for [`lookupDefaultPrintService`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/print/PrintServiceLookup.html#lookupDefaultPrintService), which is the underlying Java method the system function is calling. Unfortunately, you're at the mercy of your OS and Java's interaction with each other.

It looks like the JDK shells out to a native method:

> <https://github.com/openjdk/jdk/blob/3fbccb01dcffe9eb48a08d99aab0e9aa311a18cf/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java#L353>

Which itself apparently calls out to the Windows registry:

> <https://github.com/openjdk/jdk/blob/3fbccb01dcffe9eb48a08d99aab0e9aa311a18cf/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp#L71>

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 4, 2024, 6:15pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/7 "2024-01-04T18:15:01Z")

</div>

Have you restarted the gateway service since you set up the default? The service is independent of what you do on the desktop.

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [January 4, 2024, 6:28pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/8 "2024-01-04T18:28:27Z")

</div>

Yes, that was one of the first things we tried.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 4, 2024, 6:37pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/9 "2024-01-04T18:37:08Z")

</div>

Just want to confirm, but when you RDP into the machine to check the default printer, are you using the exact same account as the Ignition service? Default printers are on a per-user basis I believe, so if one hasn't been set up for the user yet, it may not have one or is set to the PDF printer which is probably going nowhere.

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [January 4, 2024, 6:55pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/10 "2024-01-04T18:55:27Z")

</div>

Sometimes I can't see the obvious. That was it! Thank you, sir!

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [January 4, 2024, 10:50pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-returns-null/83803/12 "2024-01-04T22:50:21Z")

</div>

Thanks for pointing that out. I've changed the solution to the correct place.
