Jump to content

Changing the owner of a Windows Service ?


Recommended Posts

Hello everyone,

Can someone tell me how to change a Service account ?

For example, my Service is launched with the local system account.

I'd like to change it programatically.

I read many posts in this forum, explaining how to get the state of a service, how to set the state service ......... But I didn't find how to change the account used to launch the service.

Is a function like : _ChangeServiceAccount ($sServiceName, $login, $password) exists ?

Thank you for your help.

Link to comment
Share on other sites

I'm sure he has his reasons, Volly.

In a standard, three-tier business logic environment, for example, processes/services often have to run as certain users (as opposed to Local System) on the application machine for security reasons. It's entirely reasonable to want a programmatic way to change process/service identity in this case.

Here's a good function for getting the service startup account name in WinXP:

Func _ServiceGetStartName($sName, $sComputerName = ".")
    $Service = ObjGet("winmgmts:\\" & $sComputerName & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objItem in $sItems
        If $objItem.Name = $sName Then Return $objItem.StartName
    Next
EndFunc

I'll have a SET function written up for you in a bit.

-S

Edited by Locodarwin
(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Link to comment
Share on other sites

Func _ServiceSetStartName($sName, $sLogin, $sPassword, $sComputerName = ".")
    $Service = ObjGet("winmgmts:\\" & $sComputerName & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objItem in $sItems
        If $objItem.Name = $sName Then
            $objItem.Change(Default, Default, Default, Default, Default, Default, $sLogin, $sPassword)
        EndIf
    Next
EndFunc

Good luck with it! :)

-S

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...