6

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.

Carey Gregory
  • 6,836
  • 2
  • 26
  • 47
Redwood
  • 66,744
  • 41
  • 126
  • 187
  • 1
    Is it true that the user can print to a printer on another domain *without* providing a valid logon for that domain? I don't know myself but I'm wondering if maybe the print server's domain is good enough. – Roger Rowland Aug 06 '13 at 07:39
  • 3
    This was originally logged as a [bug](http://support.microsoft.com/kb/156473) in NT 4.0 >pUserName member of JOB_INFO_2 structure does not include domain information. – randcd Aug 11 '13 at 06:02
  • @randcd - the link doesn't go to the right place. – Carey Gregory Aug 11 '13 at 06:07
  • @CareyGregory it works ok for me. What's wrong with the page? The issue reported is one of a number listed in the same article, though at the time this was a GDI structure or was lumped in with them for the sake of the bug. Perhaps it was never addressed since the use case would be rather fringe. – randcd Aug 11 '13 at 06:19
  • @randcd - Sorry, I was looking for a more detailed report on the bug, but now I see what you're referring to. I guess this tells us how soon Microsoft will be fixing it. NT4 is, what, 13 years obsolete? – Carey Gregory Aug 11 '13 at 06:58

2 Answers2

1

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.

Stuart
  • 1,428
  • 11
  • 20
  • I know it does not include the domain for a user on the same domain, but it does seem like it's worth checking to confirm that the behavior is the same for a user from a different domain. – Redwood Aug 10 '13 at 05:40
  • I don't have access to an environment where I can check this myself, so if you do check this out then please share the results. – Stuart Aug 12 '13 at 00:32
1

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.

Community
  • 1
  • 1
Cakez0r
  • 338
  • 1
  • 9
  • Post working code that demonstrates your idea and it's worth 50 points to you. There is a 24-hour grace period on the bounty. – Carey Gregory Aug 13 '13 at 03:57