HowTo: Enable disabled services
If you want to automate startups on services that might be disabled by GPO, you can use Win32_Service class and change properties like the startup (Automatic\Manual\Disabled) or start\stop the service.
In my case, I prefer to use themes on my XP machine at work but our GPO disables them so our machines look like NT desktops... it sucks ain't it?
So to overcome this, I placed the script in my startup to enable the Themes and start the service.
Code Snippet:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'Themes'")
For Each objService in colServiceList
'Wscript.Echo objService.Name
errReturnCode = objService.Change( , , , , "Automatic")
If objService.State <> "Running" Then
objService.StartService()
Else
objService.StopService()
Wscript.Echo "Stopping..."
Wscript.Sleep 5000
objService.StartService()
Wscript.Echo "Applying Themes"
Wscript.Sleep 5000
End If
Next
I prefer to use Cscript when executing any vbs scripts to avoid having to click on message prompts whenever you Echo.
If at first you fail, call it version 1.0
0 comments:
Post a Comment