Iâ??m trying to write an application to enumerate all the services running on
all of the servers in the company I work for. Iâ??ve got it working except that
I have not been able find how to pull the account that starts the service.
This is important because once I know this info for all the servers, I have
to write an app that will periodically change the passwords used by the
accounts starting these services. I donâ??t want to logon to all of these
servers individually to do this. Iâ??ve been able to get the information from
many of the servers by pulling the info from the registry, but many of the
servers have remote registry disabled.

Re: Retrieving account starting service by Luc

Luc
Fri Mar 25 22:54:02 CST 2005

You should use the service controller manager to perform all services
related queries/changes.
Look at the System.ServiceProcess.ServiceController Class for a start.

/LM

"Bill Richards" <Bill Richards@discussions.microsoft.com> wrote in message
news:EE4E37C8-AAE0-424B-84FF-DF0B0B8B2C5E@microsoft.com...
> I'm trying to write an application to enumerate all the services running
> on
> all of the servers in the company I work for. I've got it working except
> that
> I have not been able find how to pull the account that starts the service.
> This is important because once I know this info for all the servers, I
> have
> to write an app that will periodically change the passwords used by the
> accounts starting these services. I don't want to logon to all of these
> servers individually to do this. I've been able to get the information
> from
> many of the servers by pulling the info from the registry, but many of the
> servers have remote registry disabled.



Re: Retrieving account starting service by BillRichards

BillRichards
Sat Mar 26 00:33:02 CST 2005

That's what I'm using now, but I can not find how to access what account is
starting the services. The ServiceController returns everything else, but not
the account that starts the service.

Bill

"Luc E. Mistiaen" wrote:

> You should use the service controller manager to perform all services
> related queries/changes.
> Look at the System.ServiceProcess.ServiceController Class for a start.
>
> /LM
>
> "Bill Richards" <Bill Richards@discussions.microsoft.com> wrote in message
> news:EE4E37C8-AAE0-424B-84FF-DF0B0B8B2C5E@microsoft.com...
> > I'm trying to write an application to enumerate all the services running
> > on
> > all of the servers in the company I work for. I've got it working except
> > that
> > I have not been able find how to pull the account that starts the service.
> > This is important because once I know this info for all the servers, I
> > have
> > to write an app that will periodically change the passwords used by the
> > accounts starting these services. I don't want to logon to all of these
> > servers individually to do this. I've been able to get the information
> > from
> > many of the servers by pulling the info from the registry, but many of the
> > servers have remote registry disabled.
>
>
>

Re: Retrieving account starting service by Luc

Luc
Sat Mar 26 12:17:20 CST 2005

Damn, you are right. Although I wrote services in .NET, I still use the
management tools (in plain C) I wrote for the SCM at the time of the first
beta of NT circa 1991/1992...
I see the ServiceInstaller has the Account/Username/Password info, but no
way to connect that to an existing service.

Let's hope someone else come on with a pure .NET solution (if it is
possible). You can of course use the SCM interface with PInvoke.

/LM

"Bill Richards" <BillRichards@discussions.microsoft.com> wrote in message
news:D8981676-B1AA-47E2-84CE-60736028A3BC@microsoft.com...
> That's what I'm using now, but I can not find how to access what account
> is
> starting the services. The ServiceController returns everything else, but
> not
> the account that starts the service.
>
> Bill
>
> "Luc E. Mistiaen" wrote:
>
>> You should use the service controller manager to perform all services
>> related queries/changes.
>> Look at the System.ServiceProcess.ServiceController Class for a start.
>>
>> /LM
>>
>> "Bill Richards" <Bill Richards@discussions.microsoft.com> wrote in
>> message
>> news:EE4E37C8-AAE0-424B-84FF-DF0B0B8B2C5E@microsoft.com...
>> > I'm trying to write an application to enumerate all the services
>> > running
>> > on
>> > all of the servers in the company I work for. I've got it working
>> > except
>> > that
>> > I have not been able find how to pull the account that starts the
>> > service.
>> > This is important because once I know this info for all the servers, I
>> > have
>> > to write an app that will periodically change the passwords used by the
>> > accounts starting these services. I don't want to logon to all of these
>> > servers individually to do this. I've been able to get the information
>> > from
>> > many of the servers by pulling the info from the registry, but many of
>> > the
>> > servers have remote registry disabled.
>>
>>
>>



Re: Retrieving account starting service by Willy

Willy
Sat Mar 26 15:53:08 CST 2005


"Bill Richards" <Bill Richards@discussions.microsoft.com> wrote in message
news:EE4E37C8-AAE0-424B-84FF-DF0B0B8B2C5E@microsoft.com...
> Iâ??m trying to write an application to enumerate all the services running
> on
> all of the servers in the company I work for. Iâ??ve got it working except
> that
> I have not been able find how to pull the account that starts the service.
> This is important because once I know this info for all the servers, I
> have
> to write an app that will periodically change the passwords used by the
> accounts starting these services. I donâ??t want to logon to all of these
> servers individually to do this. Iâ??ve been able to get the information
> from
> many of the servers by pulling the info from the registry, but many of the
> servers have remote registry disabled.

Using System.Management (WMI wrappers) is the best way to manage services
and processes.

Here is a sample that retrieves the identity of the alerter service.

...
string name = "alerter";
string CIMObject = String.Format("win32_Service.Name='{0}'", name);
using(ManagementObject mo = new ManagementObject(CIMObject))
{
mo.Get();
string StartName = mo["StartName"].ToString();
Console.WriteLine(StartName);
}

Changing the identity and password can be done by invoking the "Change"
method.

ManagementBaseObject inParams = null;
inParams = srvc.GetMethodParameters("Change");
inParams["StartName"] = Name;
inParams["StartPassword"] = Password;
ManagementBaseObject outParams = srvc.InvokeMethod("Change",
inParams, null);
int ret =
System.Convert.ToInt32(outParams.Properties["ReturnValue"].Value);

For detailed info on WMI classes and methods check MSDN.

Willy.