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 winlong 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.