views:

19

answers:

1

Ok, I am trying to print a page from a windows service that I installed using a Visual Studio setup project.

At first I set the Account property yo Local System, but it will tell me that there are no printers installed (and there are). So I changed it to user and now it just doesn't print (no error or anything).

I did some Googleing and basically it said that "Interact with Desktop" should be enabled. To programatically do this you need to edit the registry settings for this service (which really is second prize). I tried to manually set it on the properties dialog under Services, but then I need to change the Account back to Local System, which brings me back to the "No Printers Installed" problem.

Any ideas?

+1  A: 

I wouldn't recommend using interact with desktop. You will run into compatibility problems on Vista, Windows 7, and later versions of Windows.

You could use WTSQueryUserToken to get a user token for a logged on user and then print from that user's token. You could do this using CreateProcessAsUser to do the actual printing.

To get the logged on sessions you could use WTSGetActiveConsoleSessionId or WTSEnumerateSessions.

Brian R. Bondy