Retrieving the user domain name for a print job from the Print Spooler API

How to get the domain name of the user doing the print with the print job ID?

I can get the username from, for example, JOB_INFO_2 retrieved via GetJob, but none of the JOB_INFO_ # structures contain the domain name of the user.

I can get the print server domain using IPGlobalProperties.GetIPGlobalProperties().DomainName , but it may not be the same as the user domain, so it is not a reliable solution.

+6
source share
2 answers

I don’t know for sure, but it seems to me that perhaps the username will include the user's domain (somelike name @domain), and perhaps this will only happen if the user prints to a printer in a different domain. It might be worth writing the code and checking it out.

+1
source

Try using UserPrincipal.FindByIdentity (PrincipalContext, IdentityType, String) to find the user by username. Once the user is found, get the domain with this UserPrincipal Context property.

You need to add a link to System.DirectoryServices.AccountManagement.

+1
source

Source: https://habr.com/ru/post/950651/


All Articles