[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

Windows services

Is there a way to create a windows service to run as any user rather than the SYSTEM?
-->
1) I created a C#.net service application to do something.
2) For testing purposes i used the command:: sc create serviceName binPath="...." start= "auto" depend= "Tcpip"
-->
When I look at Windows Task Manager. The process owner(User Name) that is associate with this service is "SYSTEM". I want this service to run as the local user but not restricted to this. If another user logs in I want his name listed as the username of this service.

Is there a way to do this?
0
asukhu
Asked:
asukhu
  • 4
  • 3
1 Solution
 
Donald StewartNetwork AdministratorCommented:
Services will only run as the user they were initially configured with, what is the reason you need this to run as the locally logged on user?

We should be able to find a workaround/other option for this.
0
 
WilliamCommented:
Why not run it as an application and place it in the startup dir or add it to the registry - this way it will always start when someone logs on, and as the logged on user.
Unless it is performing stuff at startup of windows this should work...
0
 
asukhuAuthor Commented:
I am trying to automate printing. I can print to any physical printer but when I try to print to like Cutepdf or doPdf the print job gets stuck in the print queue. I was thinking that it is because the owner of the print job is "SYSTEM" rather than the local user. I can run it as regular application just fine but I need it as a service because if the application for some reason die I want it to start it up again. And windows service manager handles that.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
WilliamCommented:
Why not create a user in the domain for this service - if it is hanging in the queue do to the credentials - this would allow access for printing and running on the local machines as needed.
0
 
asukhuAuthor Commented:
I dont want to do that because the "System" account is a level above Administrator and I dont want anyone to have administrator rights besides myself or any other admins.
0
 
WilliamCommented:
Do you have an UnhandledException handler in your service?
0
 
asukhuAuthor Commented:
no, I did not get an exception.
0
 
WilliamCommented:
The use of the Printing classes is not supported from a service or ASP page. Therefore, if printing is required in this scenario, then a second service must be written, using only Win32 APIs. This service would then print at the request of the ASP page or .NET service. The request can be made by means of Interprocess Communication (IPC), such as a named pipe, event, shared section, or similar means.

The following are some cautions for printing from Win32 services: If all the print jobs can be sent with one user's credentials, the service can be run under that user's account and will have access to the printers that are known to that user on that computer. If the service must print using the credentials of one or more users defined at run time, then the service must LogonUser(), LoadUserProfile(), and ImpersonateLoggedOnUser() before printing. If the user has never logged on to the server computer before, the service must also AddPrinterConnection() as appropriate. This approach will leave residue behind in the form of printer connections, registry hives, per-user directories on the hard disk, and others.

Taken from:
http://support.microsoft.com/kb/324565 
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now