Page 1 of 1 1
Topic Options
#201581 - 2011-02-14 07:39 PM Enable a Disabled Windows Service (Automatic Update)
TimE Offline
Fresh Scripter

Registered: 2009-08-17
Posts: 5
Loc: Jacksonville, FL
I need to make sure "wuauserv" is enabled on all my Windows machines. I have a GPO for WSUS but I noticed that if the Startup Type is set to "Disable" GPO will not work. How do I (1) change the startup type to "Automatic" and (2) once changed to Automatic start the service.

Any guidance will be greatly appreciated.

Top
#201586 - 2011-02-14 09:26 PM Re: Enable a Disabled Windows Service (Automatic Update) [Re: TimE]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Welcome to KORG!

There are several UDFs available to manage services, including WMIService and WMISvcMgr. The latest copy of WMISvcMgr can be obtained from the UDF Library in the Resources section of my web site. You'll also find a complete library of WSUS functions there along with a sample script to control the download and installation of updates via WSUS. The script integrates with a scheduled task to repeatedly download and install updates during a defined change window until all updates are applied. Without this, WSUS only installs the dependent changes and waits until the next change period to continue installing.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#201587 - 2011-02-14 09:34 PM Re: Enable a Disabled Windows Service (Automatic Update) [Re: Glenn Barnas]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
As Glenn pointed out, there are several already completed UDFs readily available for handling services. But here is a small example that I just wrote up that accomplishes what you specifically asked for. You can play around with it, and look at Glenn's suggestions for more advanced options.

 Code:
$ServiceStatus = IsServiceRunning("wuauserv")

If $ServiceStatus[0] = "Running"
   ? "Automatic Updates is Running"
   If InStr($ServiceStatus[1],"Auto")
      ? "Automatic Updates is set to Auto"
   Else
      If ChangeServiceState("wuauserv","Automatic")=0
         ? "Automatic Updates Has Been Set to AUTO"
      Else
         ? "Error Setting Automatic Updates to AUTO"
      Endif
   EndIf
Else
   If ChangeServiceRunState("wuauserv","Start")=0
      ? "Automatic Updates Has Been Started"
      If ChangeServiceState("wuauserv","Automatic")=0
         ? "Automatic Updates Has Been Set to AUTO"
      Else
         ? "Error Setting Automatic Updates to AUTO"
      EndIf
   Else
      ? "Error Starting Automatic Updates, Still not Running"
   EndIf
EndIf

get $

Function IsServiceRunning($svc)
; Returns a 2 element array with the Running status[0] and the start mode [1]
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+@WkSta+"\root\cimv2")
   $colListOfServices = $objWMIService.ExecQuery("Select * from Win32_Service WHERE Name='$svc'")
   For Each $objService in $colListOfServices
      $IsServiceRunning = $objService.State,$objService.StartMode
   Next
EndFunction

Function ChangeServiceState($svc,$state)
;Call function with either 'Automatic','Manual', or 'Disabled'
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+@WkSta+"\root\cimv2")
   $colListOfServices = $objWMIService.ExecQuery("Select * from Win32_Service WHERE Name='$svc'")
   For Each $objService in $colListOfServices
      $ChangeServiceState = $objService.ChangeStartMode($state)
   Next
EndFunction

Function ChangeServiceRunState($svc,$runstate)
;Call function with either 'Start' or 'Stop'
   $objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+@WkSta+"\root\cimv2")
   $colListOfServices = $objWMIService.ExecQuery("Select * from Win32_Service WHERE Name='$svc'")
   For Each $objService in $colListOfServices
      If $runstate="Start"
         $ChangeServiceRunState = $objService.StartService()
      Else
         If $runstate="Stop"
            $ChangeServiceRunState = $objService.StopService()
         Else
           Exit 87
         EndIf
      EndIf
   Next
EndFunction

Top
#201588 - 2011-02-14 09:40 PM Re: Enable a Disabled Windows Service (Automatic Update) [Re: TimE]
Tesdall Offline
Getting the hang of it

Registered: 2009-10-02
Posts: 78
Loc: USA
you could do something like this:

 Code:
Break on
Writevalue('HKLM\system\currentcontrolset\services\wuauserv', 'Start', "2", "REG_DWORD")
net start "wuauserv"
Exit


Something like that anyway.

for reference:
 Code:
         Boot        0x0
         System      0x1
         Automatic   0X2
         Manual      0x3
         Disabled    0x4



/Quick and Dirty


Update:
Or you can just do what Citrixman says \:\)


Edited by Tesdall (2011-02-14 09:41 PM)
Edit Reason: Being quick and Dirty
_________________________
Where ever you go, there you are.

Top
#201593 - 2011-02-14 10:35 PM Re: Enable a Disabled Windows Service (Automatic Update) [Re: ShaneEP]
TimE Offline
Fresh Scripter

Registered: 2009-08-17
Posts: 5
Loc: Jacksonville, FL
Thanks Citrix Man!!! It works great, I just have to make a few modifications for it to work in my environment.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 317 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.052 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org