[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Windows Service Change credentials and remote access (Urgent)

Posted on 2006-11-13
10
Medium Priority
?
589 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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