Magellan Posted July 23, 2007 Share Posted July 23, 2007 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 More sharing options...
Magellan Posted July 26, 2007 Author Share Posted July 26, 2007 Any ideas ? Thanks Link to comment Share on other sites More sharing options...
Bert Posted July 26, 2007 Share Posted July 26, 2007 ummm. why would you want to do this? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Locodarwin Posted August 1, 2007 Share Posted August 1, 2007 (edited) 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 August 1, 2007 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 More sharing options...
Locodarwin Posted August 1, 2007 Share Posted August 1, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now