service
i want to disable a service them start it under and different username and password how can i do that, i know how to stop the services but i don't know how to start it under and different user
this is what i have so far
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='iPod Service'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
this is what i have so far
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='iPod Service'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
0 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
spartacus
18 years ago
In the following script, replace DOMAIN\USERNAME and PASSWORD with your actual values :
[NB: This won't work inside a Windows Installer custom action (if that's what you plan to do) because of the references to wscript.quit and wscript.sleep. If you need to acheive this in an MSI, have a look at the Windows Installer SDK documentation on the ServiceControl table and use that instead.
Regards,
Spartacus
Option Explicit
Const ServiceToChange = "iPod Service"
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep
strComputer = "."
intSleep = 10000
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service")
For Each objService in colListOfServices
if objService.Name = ServiceToChange then
' Alter credentials for service to run under
objService.Change , , , , , ,"DOMAIN\USERNAME","PASSWORD"
objService.StopService()
wscript.sleep intSleep
objService.StartService()
exit for
end if
Next
WScript.Quit
[NB: This won't work inside a Windows Installer custom action (if that's what you plan to do) because of the references to wscript.quit and wscript.sleep. If you need to acheive this in an MSI, have a look at the Windows Installer SDK documentation on the ServiceControl table and use that instead.
Regards,
Spartacus
Posted by:
linstead
18 years ago
Posted by:
spartacus
18 years ago
I don't believe this is possible via a script, you would need to create a compiled exe that makes use of the LsaAddAccountRights function.
An alternative would be to look at using the NTRIGHTS utility - if a scripted solution is needed, you could always shell out to NTRIGHTS (bit kludgy, I know ).
Regards,
Spartacus
An alternative would be to look at using the NTRIGHTS utility - if a scripted solution is needed, you could always shell out to NTRIGHTS (bit kludgy, I know ).
Regards,
Spartacus
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.