Solved

Windows Service Change credentials and remote access (Urgent)

Posted on 2006-11-13
10
582 Views
Last Modified: 2007-11-27
Hi,

Is it possible to programatically change the logon credentials for a windows service after it is installed?

The case is: I'm writing a windows service to be installed on a server, and controlled from an admin app. At some point the admin will need to make the service log on using a different account to perform certain operations (it doesn't matter if it has to restart).

Also I need to control the service from a remote computer in the same domain, do I have to set up a remoting connection, or only change domain user access?
0
Comment
Question by:Harlequin_
[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
  • 6
  • 4
10 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17929941
When you says "control" the serveice do you mean stop, start pause, continue, restart ?
Wndows already provides and interface to doing this.
You can also set the account used by a service easily both locally and remotely, are you sure you want to do it programmatically ?
0
 

Author Comment

by:Harlequin_
ID: 17929998
>When you says "control" the serveice do you mean stop, start pause, continue, restart ?
Yes, plus the ExecuteCommand(int) / OnCustomCommand(int) to make the service perform custom commands on demand.

>Wndows already provides and interface to doing this.
Yes, but I am building a simplified admin tool for relatively novice users, and would like to let them use only one app for all functionality.

>You can also set the account used by a service easily both locally and remotely, are you sure you want to do it programmatically ?
Yes, for the same reasons.

The most urgent part is to be able to run custom commands from a different computer (using the admin app).
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17930241
Are you using the ServiceController class ?

ServiceController controller = new ServiceController("servicename", "remotemachinename");
controller.Start();
controller.Stop();
controller.ExecuteCommand(int);

etc ?
0
Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 15

Expert Comment

by:ozymandias
ID: 17930265
If you cannot only use ExecuteCommand I think you can generate a proxy class for the remote service object using controller.CreateObjRef(Type);

Still not sure how you would set/change the service account username/password.
0
 

Author Comment

by:Harlequin_
ID: 17930308
Yes, I'm using ServiceController, and I don't need other than start/stop/executecommand etc.

Do you know what permissions is needed to use the servicecontroller to control a windows service on a different computer?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17930519
I think it will depend on the local policies on the machine but I'm not sure what the defaults are.
0
 

Author Comment

by:Harlequin_
ID: 17930882
I'll do some more reading tonight. Just found out that ExecuteCommand only accepts integers betweer 128 & 256.. :-\

Do you have a complete example of using controller.CreateObjectRef(Type) - objectRef.GetRealObject - etc with all the remoting settings needed?
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17934420
I'm afraid I don't have any examples of this but I think its fairly routine remoting stuff so there should be lots of examples available.

As for changing the account and password used for running the service you need this :

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern Boolean ChangeServiceConfig(IntPtr hService, UInt32 nServiceType, UInt32 nStartType, UInt32 nErrorControl, String lpBinaryPathName, String lpLoadOrderGroup, IntPtr lpdwTagId, String lpDependencies, String lpServiceStartName, String lpPassword, String lpDisplayName);


For more information on how to use this method see : http://www.pinvoke.net/default.aspx/advapi32.ChangeServiceConfig
0
 

Author Comment

by:Harlequin_
ID: 17936871
I think this is as far I'll get without doing more research myself :)

Thanks for your help!
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17936947
No problem. Good luck.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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