Solved

Windows services

Posted on 2009-04-06
8
427 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: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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

930 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

14 Experts available now in Live!

Get 1:1 Help Now