Solved

Windows services

Posted on 2009-04-06
8
426 Views
Last Modified: 2013-12-17
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
Comment
Question by:asukhu
  • 4
  • 3
8 Comments
 
LVL 47

Expert Comment

by:dstewartjr
Comment Utility
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
 
LVL 11

Expert Comment

by:William
Comment Utility
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
 

Author Comment

by:asukhu
Comment Utility
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
 
LVL 11

Expert Comment

by:William
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:asukhu
Comment Utility
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
 
LVL 11

Expert Comment

by:William
Comment Utility
Do you have an UnhandledException handler in your service?
0
 

Author Comment

by:asukhu
Comment Utility
no, I did not get an exception.
0
 
LVL 11

Accepted Solution

by:
William earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now