Solved

Windows services

Posted on 2009-04-06
8
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 47

Expert Comment

by:Donald Stewart
ID: 24077853
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
ID: 24078827
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
ID: 24078907
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 11

Expert Comment

by:William
ID: 24078947
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
 

Author Comment

by:asukhu
ID: 24081694
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
ID: 24082078
Do you have an UnhandledException handler in your service?
0
 

Author Comment

by:asukhu
ID: 24082100
no, I did not get an exception.
0
 
LVL 11

Accepted Solution

by:
William earned 500 total points
ID: 24082126
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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!    …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

730 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