Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I am attempting to run an application under a windows service that prints a document using the system account. To do this I follow the following steps using C# and the win32 API.

WTSGetActiveConsoleSessionID - to get the current console session to run the print application in.
CreateToolhelp32Snapshot - to find the winlogon porccess
OpenProcess - to open the winlogon process
OpenProcessToken, LookupPrivilegeValue and DuplicateTokenEx to create a duplicate of the winlogon user token.
SetTokenInformation - to set the session to 1
AdjustTokenPrivileges
CreateEnvironmentBlock
CreateProcessAsUser - to start the print

So far I have tested this process on Windows 2003, 2008, and 7 and it works fine, on 2012 though it will not print. In the task manager I can see activity in spoolsv.exe as it process the print and splwow46.exe starts. There are no errors.

I have also made the following registry changes to set up a default printer. http://support.microsoft.com/kb/184291 (and for HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion)

Does anyone have an insight into printing from a session account? I have used PsExec.exe to run the print process under the system account as well and see the same behavior and no printed output. The same print application works on the 2012 machine when run by me.
Posted
Updated 14-Nov-13 7:46am
v2
Comments
btompkin 14-Nov-13 16:11pm    
It looks like my problem was using a network printer. Tested this with a local printer and it worked fine. Still don't know what the problem was with the network printer, permissions maybe.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900