Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the user's domain name for a print job from the Print Spooler API

How can I get the domain name of the user making a print given the Job ID of the print?

I can get the user's name from, e.g., the JOB_INFO_2 retrieved via GetJob, but none of the JOB_INFO_# structures contain the user's domain name.

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

like image 898
Lawrence Johnston Avatar asked Jul 30 '13 18:07

Lawrence Johnston


2 Answers

I don't know for sure, but it occurs to me that maybe the user name will include the user's domain (somelike name@domain), and maybe that only happens if the user is printing to a printer in another domain. It might be worth writing some code and checking this out.

like image 134
Stuart Avatar answered Nov 16 '22 22:11

Stuart


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

You'll need to add a refernce to System.DirectoryServices.AccountManagement.

like image 27
Cakez0r Avatar answered Nov 16 '22 23:11

Cakez0r