Search code examples
printingxps

How to find or add the username of the printing user to an XPS printed with XPSDrv


Does anyone know if there is a simple way to include the username of the printing user somewhere accessible either in the XPS package or in any header in the data stream from the driver when using XPSDrv? By using a filter in the filter pipeline (even though it is not simple in my opinion)? By reading TCP/IP header values? I have googled my fingers short trying find a reasonable solution.


Solution

  • Simple? No, not really. Your best bet is probably to modify a filter in your XPS driver to do the following:

    1. Extract the user token from the pipeline's property bag using the XPS_FP_USER_TOKEN key.
    2. Get the user's SID from the token using GetTokenInfo
    3. Get the username from the SID using LookupAccountSID
    4. Add the username to the print ticket. To keep things as simple as possible, I'd suggest reusing a field from the public schema, such as the JobComment ParameterInit.

    This is all just a starting point. I suspect you're going to need to delve into the details of how an XPS driver works in order to make this a reliable solution.