Solved

Windows Service Change credentials and remote access (Urgent)

Posted on 2006-11-13
10
569 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_
  • 6
  • 4
10 Comments
 
LVL 15

Expert Comment

by:ozymandias
Comment Utility
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_
Comment Utility
>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
Comment Utility
Are you using the ServiceController class ?

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

etc ?
0
 
LVL 15

Expert Comment

by:ozymandias
Comment Utility
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_
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

by:ozymandias
Comment Utility
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_
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
No problem. Good luck.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

10 Experts available now in Live!

Get 1:1 Help Now