Open tresf opened 8 years ago
In windows 7 I was able to create a service using nssm install qztray javaw -DtrustedRootCert=C:\cert\mycert.pem "-jar \"C:\Program Files\QZ Tray\qz-tray.jar\""
and editing the created C:\Windows\System32\config\systemprofile\AppData\Roaming\qz\allowed.dat
file with the location I needed to allow.
Looking forward to a more straightforward solution in 2.2!
@cwg999 another client tested out your solution and shared the following with us...
- Make sure QZ Tray is downloaded and installed.
- Make sure you can already print with QZ Tray (click "Always allow" at least once)
- Download
nssm
, extract to e.g. the Desktop- Open
cmd
as Administrator- Navigate to the 64-bit version of nssm, e.g.
cd "%USERPROFILE%\Desktop\nssm-2.24\win64\"
- Execute the command to install the service using nssm:
REM set OPTS=-DtrustedRootCert="%USERPROFILE%\Desktop\override-cert.crt" nssm install qz-tray javaw "%OPTS% -jar """%PROGRAMFILES%\QZ Tray\qz-tray.jar"""" (svc name)^ ^(program) ^(arguments, escaped) REM FIXME Escape quotes for cmd
- Copy
prefs.properties
andallowed.dat
from location:%appdata%\qz
toC:\Windows\System32\config\systemprofile\AppData\Roaming\qz\
- (Re)Start the service via the service manager in Windows.
- Test the printing.
- Check the logs in
C:\Windows\System32\config\systemprofile\AppData\Roaming\qz\
for a positive outcome. Note: Virtual printers that show pop-ups to save the document (e.g. PDFCreator) will not be shown; this won't work when QZ Tray is running as a service.
Here's the steps I performed to get NSSM + QZ Tray working.
Download and install QZ Tray
Launch the demo page(file:///C:/Program%20Files/QZ%20Tray/demo/sample.html
), and select "Allow and Remember" to whitelist the certificate. This required because the dialogue prompts will not be displayed when running as a service.
Download NSSM. Extract this to a sane, safe location. I used C:\nssm-2.24-101-g897c7ad
Create a batch file for launching QZ Tray
full/path/to/java.exe -jar full/path/to/qz-tray.jar
in the next step@ECHO OFF
REM launch QZ Tray 2.0.x
java -Xms512M -jar "%PROGRAMFILES%\QZ Tray\qz-tray.jar" %1
REM launch QZ Tray 2.1 (headless support)
REM java -Xms512M -jar "%PROGRAMFILES%\QZ Tray\qz-tray.jar" --headless %1
Install the service
REM change dir to NSSM 64-bit directory
cd c:\nssm-2.24-101-g897c7ad\win64
REM create a service called "qz-tray" that points to your batch file
REM if you do not want a batch file, replace path of batch file with full/path/to/java.exe -jar full/path/to/qz-tray.jar
nssm install qz-tray full\path\to\qztray-service.bat
Copy %APPDATA%\qz\allowed.dat
to C:\Windows\System32\config\systemprofile\AppData\Roaming\qz\allowed.dat
copy /Y %APPDATA%\qz\allowed.dat C:\Windows\System32\config\systemprofile\AppData\Roaming\qz\allowed.dat
Verify QZ Tray is not running on the desktop
Open Services, find qz-tray, and start it
Refresh the demo page. It should now be connected.
@klabarge thanks, I've adapted these for our deployment section here: https://github.com/qzind/tray/wiki/Windows-Service
Enhancement placeholder to run QZ Tray as a Windows Service, milestoned for the 2.2 release.
Note; A prerequisite to starting this task is Headless Support (#51) which is milestoned for the 2.1 release.
Possible utilities for creating a Windows Service:
sc
command on Windows (may not be useful as a standalone tool)winrun4j
Advanced Java launcher for Windows. Claims to offer Windows service support.nssm
Claims to handle service failures better than most others.