Skip to content

Windows Service

Tres Finocchiaro edited this page Nov 21, 2019 · 35 revisions
  • ✅ 2.1 | ✅ 2.0 | ✅ 1.9 | ...

Objective

  • Run QZ Tray as a Windows service. image
  • This configuration utilizes a third party product "NSSM" to register QZ Tray as a service. It's not officially supported, but has been reported to work well by several users/environments.

Prerequisites

Steps

Prepare QZ Tray

  1. Warning: Services can NOT show the "Trusted" dialog. If not already...
    • Visit a website with the certificate that needs to be whitelisted.
    • Click "Remember this decision". This will save a file allowed.dat to %APPDATA%\qz.
  2. Open a command prompt As Administrator
  3. Create a .bat file that can launch QZ Tray
    echo wmic.exe process where "Name like '%%java%%' and CommandLine like '%%qz-tray.jar%%'" call terminate>"%PROGRAMFILES%\QZ Tray\qz-tray.bat"
    echo java.exe -Xms512M -jar "%~dp0qz-tray.jar" %*>> "%PROGRAMFILES%\QZ Tray\qz-tray.bat"
  4. Make a location for SYSTEM certificate whitelist
    mkdir "%WINDIR%\System32\config\systemprofile\AppData\Roaming\qz"
  5. Copy the allowed.dat to the SYSTEM profile
    copy /Y "%APPDATA%\qz\allowed.dat" "%WINDIR%\System32\config\systemprofile\AppData\Roaming\qz\allowed.dat"

Install the Service

  1. Open a command prompt As Administrator

  2. If not already, extract NSSM to C:\ (e.g. C:\nssm)

  3. Change to the win64 directory within NSSM.

    cd C:\nssm\win64
  4. Install the QZ Tray service

    nssm install "QZ Tray" "%PROGRAMFILES%\QZ Tray\qz-tray.bat"
    nssm set "QZ Tray" Description "Browser printing utility"
  5. Start the service

    net start "QZ Tray"
  6. Check that it's running, look for QZ Tray in the services listing.

    start services.msc

Advanced

  1. Before making any changes, make sure to stop the service
    net stop "QZ Tray"
  2. Run QZ Tray with a custom Java version (Important: change C:\Program Files\Java\jdk1.8.0_231\bin to point to a proper JDK)
    echo set PATH=C:\Program Files\Java\jdk1.8.0_231\bin;^%PATH^%> "%PROGRAMFILES%\QZ Tray\qz-tray.bat"
    echo wmic.exe process where "Name like '%%java%%' and CommandLine like '%%qz-tray.jar%%'" call terminate>>"%PROGRAMFILES%\QZ Tray\qz-tray.bat"
    echo java.exe -Xms512M -jar "%~dp0qz-tray.jar" %*>> "%PROGRAMFILES%\QZ Tray\qz-tray.bat"

Remove the Service

  1. Open a command prompt As Administrator
  2. Change to the win64 directory within NSSM.
    cd C:\nssm\win64
  3. Uninstall the QZ Tray service
    net stop "QZ Tray"
    nssm remove "QZ Tray"

Troubleshooting

  1. Make sure you can call java from a command prompt

    java -version
  2. If initial connection works, but printing, listing printers, fails, make sure you've properly configured signing. Signing-Messages

Clone this wiki locally