Snippet checks for the enabled status of microsoft updates and returns certain information about the updates management. Usage examples provided in the comments.
; /settings -> shows settings dialog
; /settings check -> returns $true if enabled, if not it tries to enable the service and then returns $true/$false depending on success.
; $settings(day) -> returns day installation of updates are scheduled for
; $settings(readonly) -> returns $true/$false readonly dependent
; $settings(level) -> returns N
; N = 0 -> Not configured by user or group policy
; N = 1 -> Disabled
; N = 2 -> Prompts users to approve updates before downloading or installing
; N = 3 -> Automatically downloads updates but prompts users to approve before installation
; N = 4 -> Automatically installs updates on user specified schedule
; $settings(required) -> returns $true/$false if updates are required
; $settings(time) -> returns time (24 hour clock with 0 as 12:00 AM) installation is scheduled for
alias -l dcom return obj $+ $com(0)
alias -l xcom .timer 1 0 .comclose $1-
alias settings {
var %% $dcom, %! . $+ %%, %&, %#
.comopen %% microsoft.update.autoupdate
if (!$isid) && (!$1) .comclose %% $com(%%,showsettingsdialog,1)
elseif (!$isid) && ($1 = check) {
%& = $r(,$com(%%,serviceenabled,2)) $com(%%).result
if (%&) {
xcom %% | echo $color(info) %&
}
else {
%& = $r(,$com(%%,enableservice,1)) $qt($com(%%).result)
xcom %% | echo $color(info) $iif(%&,$true,$false)
}
}
elseif ($isid) && ($1) {
.comclose %% $com(%%,settings,3,dispatch* %!)
if ($1 = readonly) { xcom %! | return $r(,$com(%!,readonly,3)) $com(%!).result }
elseif ($1 = required) { xcom %! | return $r(,$com(%!,required,3)) $com(%!).result }
elseif ($1 = day) {
%& = Every Day.Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday
%# = $r(,$com(%!,scheduledinstallationday,3)) $qt($com(%!).result)
if (%#) {
tokenize 46 %&
xcom %! | return $gettok(%&,$calc($noqt(%#) + 1),46)
}
}
elseif ($1 = level) {
%& = $r(,$com(%!,notificationlevel,3)) $qt($com(%!).result)
if (%&) { xcom %! | return $noqt($com(%!).result) }
}
elseif ($1 = time) {
%& = $r(,$com(%!,scheduledinstallationtime,3)) $qt($com(%!).result)
if (%&) { xcom %! | return $noqt($com(%!).result) }
}
else { xcom %! | return * $!settings: Invalid arguments. }
}
else echo $color(info) * $!settings: Invalid arguments.
}