PC Review


Reply
Thread Tools Rate Thread

Change NT Service user name and password after installation

 
 
=?Utf-8?B?QnJ1Y2UgUGFya2Vy?=
Guest
Posts: n/a
 
      25th Feb 2005
Is there a way to change a NT Service's user name and password after it has
been installed. I want to perform a check for the user name in the On_Start
event of the service. If it is not the one I want I want to change the user
name and password and then allow the service to start.
 
Reply With Quote
 
 
 
 
Sean Hederman
Guest
Posts: n/a
 
      25th Feb 2005
I'd say that your service should launch an external app which will perform
the restart. Unfortunately if the user that your service is logged in as
doesn't have permission to start and stop services, and change service
permissions then this won't work.

Is there any particular reason you want to limit the user name? I would be
very unhappy if a service told me what user name it wanted. Surely all the
service really need is the correct permissions? Also, I'd classify any
service which elevated it's own privileges as a serious security risk.
Rather just fail on start and write to the event log what you want to
happen. Then the system administrator can decide what to do.

Also, if you're looking at changing to one of the standard user id's beware
about localization issues. Also keep in mind that many network admins remove
the standard user names off their systems. One I know has no Administrator
accounts on any machine.

"Bruce Parker" <(E-Mail Removed)> wrote in message
news:67E1A786-F70D-4DA3-B5F0-(E-Mail Removed)...
> Is there a way to change a NT Service's user name and password after it
> has
> been installed. I want to perform a check for the user name in the
> On_Start
> event of the service. If it is not the one I want I want to change the
> user
> name and password and then allow the service to start.



 
Reply With Quote
 
=?Utf-8?B?QnJ1Y2UgUGFya2Vy?=
Guest
Posts: n/a
 
      25th Feb 2005
The service has to run under a specific account that we specify to the
customer. There are a lot of reasons for this but would take too long to
explain. I need a programmatic way to modify the user name and password.
The service is a .NET service and I want to perform the check in the OnStart
event. If this is not possible, I do want to launch a .NET executable to
perform this task.

How do I do this programmatically through .NET?

"Sean Hederman" wrote:

> I'd say that your service should launch an external app which will perform
> the restart. Unfortunately if the user that your service is logged in as
> doesn't have permission to start and stop services, and change service
> permissions then this won't work.
>
> Is there any particular reason you want to limit the user name? I would be
> very unhappy if a service told me what user name it wanted. Surely all the
> service really need is the correct permissions? Also, I'd classify any
> service which elevated it's own privileges as a serious security risk.
> Rather just fail on start and write to the event log what you want to
> happen. Then the system administrator can decide what to do.
>
> Also, if you're looking at changing to one of the standard user id's beware
> about localization issues. Also keep in mind that many network admins remove
> the standard user names off their systems. One I know has no Administrator
> accounts on any machine.
>
> "Bruce Parker" <(E-Mail Removed)> wrote in message
> news:67E1A786-F70D-4DA3-B5F0-(E-Mail Removed)...
> > Is there a way to change a NT Service's user name and password after it
> > has
> > been installed. I want to perform a check for the user name in the
> > On_Start
> > event of the service. If it is not the one I want I want to change the
> > user
> > name and password and then allow the service to start.

>
>
>

 
Reply With Quote
 
William DePalo [MVP VC++]
Guest
Posts: n/a
 
      25th Feb 2005
"Bruce Parker" <(E-Mail Removed)> wrote in message
news:67E1A786-F70D-4DA3-B5F0-(E-Mail Removed)...
> Is there a way to change a NT Service's user name and password after it
> has
> been installed. I want to perform a check for the user name in the
> On_Start
> event of the service. If it is not the one I want I want to change the
> user
> name and password and then allow the service to start.


FWIW:

I don't know enough about .Net to know what your options are there.

If you find that it doesn't have support for what you want to do, and if you
are comfortable operating at the level of the Win32 API then you can use
OpenSCManager(), OpenService(), ChangeServiceConfig() to alter an installed
service's parameters. If you go that route, don't forget to close any
handles that you open.

Regards,
Will


 
Reply With Quote
 
Sean Hederman
Guest
Posts: n/a
 
      26th Feb 2005
From the looks of things you'll have to use P/Invoke for this. The
ServiceController doesn't have a Restart method, nor does it provide access
to the user credentials. You could get around the Restart issue by spawning
another process that starts the service (say, "net start myservice") on
service stop.

"Bruce Parker" <(E-Mail Removed)> wrote in message
news:904D1E93-64EF-403B-804D-(E-Mail Removed)...
> The service has to run under a specific account that we specify to the
> customer. There are a lot of reasons for this but would take too long to
> explain. I need a programmatic way to modify the user name and password.
> The service is a .NET service and I want to perform the check in the
> OnStart
> event. If this is not possible, I do want to launch a .NET executable to
> perform this task.
>
> How do I do this programmatically through .NET?
>
> "Sean Hederman" wrote:
>
>> I'd say that your service should launch an external app which will
>> perform
>> the restart. Unfortunately if the user that your service is logged in as
>> doesn't have permission to start and stop services, and change service
>> permissions then this won't work.
>>
>> Is there any particular reason you want to limit the user name? I would
>> be
>> very unhappy if a service told me what user name it wanted. Surely all
>> the
>> service really need is the correct permissions? Also, I'd classify any
>> service which elevated it's own privileges as a serious security risk.
>> Rather just fail on start and write to the event log what you want to
>> happen. Then the system administrator can decide what to do.
>>
>> Also, if you're looking at changing to one of the standard user id's
>> beware
>> about localization issues. Also keep in mind that many network admins
>> remove
>> the standard user names off their systems. One I know has no
>> Administrator
>> accounts on any machine.
>>
>> "Bruce Parker" <(E-Mail Removed)> wrote in message
>> news:67E1A786-F70D-4DA3-B5F0-(E-Mail Removed)...
>> > Is there a way to change a NT Service's user name and password after it
>> > has
>> > been installed. I want to perform a check for the user name in the
>> > On_Start
>> > event of the service. If it is not the one I want I want to change the
>> > user
>> > name and password and then allow the service to start.

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change user password in ADS and check the password policy? Volkan Senguel Microsoft C# .NET 0 19th Aug 2009 07:49 PM
How can Administrator change the Password of existing User, without knowing his Old Password in Administer Security Tool ? Luqman Microsoft ASP .NET 5 12th Jul 2007 10:29 AM
How to get username, password from .NET Windows service installation to actual service code ? jimmy Microsoft C# .NET 0 31st Jan 2007 10:02 PM
Other user account able to change my password without old password prompt noddyt Windows XP Security 1 12th Aug 2005 11:29 PM
service installation with user account Lukasz Microsoft ASP .NET 2 7th Apr 2004 11:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:50 PM.