Skip to content

Windows Service

Kyle La Barge edited this page Dec 16, 2021 · 35 revisions
  • ✅ 2.2 | ✅ 2.1 | ✅ 2.0 | ✅ 1.9 | ...

Objective

  • Run QZ Tray as a Windows service.
  • 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. If upgrading from QZ Tray version 2.x to 2.2, the old service must be removed

  2. 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.
  3. Open a command prompt As Administrator

  4. Create a .bat file that can launch QZ Tray (the below commands will create this file)

    • QZ Tray 2.2 and newer (Bundled Java)
      echo wmic.exe process where "Name like '%%java%%' and CommandLine like '%%qz-tray.jar%%'" call terminate>"%PROGRAMFILES%\QZ Tray\qz-tray.bat"
      echo "%PROGRAMFILES%\QZ Tray\runtime\bin\java.exe" -Xms512M -jar "%~dp0qz-tray.jar" %*>> "%PROGRAMFILES%\QZ Tray\qz-tray.bat"
    • QZ Tray 2.1 and lower
      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"
  5. Disable auto-start of QZ Tray for ordinary users:

    echo 0 > "%PROGRAMDATA%\qz\.autostart"
  6. Make a location for SYSTEM certificate whitelist

    mkdir "%WINDIR%\System32\config\systemprofile\AppData\Roaming\qz"
  7. Copy the allowed.dat to the SYSTEM profile

    copy /Y "%APPDATA%\qz\allowed.dat" "%WINDIR%\System32\config\systemprofile\AppData\Roaming\qz\allowed.dat"
    • 32-bit Java will need to change this to %WINDIR%\SysWOW64 instead.

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
  7. That's it, the QZ Tray service has been successfully installed.

Advanced

Run with a dedicated Java version

  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"
  4. Re-enable autostart for regular users
    del "%PROGRAMDATA%\qz\.autostart"

Troubleshooting

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

    java -version
    • If java is not available, you may hardcode the path using Advanced section above.
  2. If initial connection works, but printing, listing printers, fails, make sure you've properly configured signing. Signing