Jump to content
botanic

Script to run windows update

Recommended Posts

botanic

Does anyone have any idea of a way to make a script that will auto download and install windows updates? I have looked online for command line tools and found nothing ^_^

Share this post


Link to post
Share on other sites
Melba23

botanic,

I am confused (not altogether rare!). Does Windows not do this for you already? Why do you need a script?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
botanic

i work at a data center and i want to install the script to run on first boot so that i dont have to goto windows update and can just install the server, have it update, and be done with it. Installing windows 2003 a few hundred times can be a real chore ;)

and i cant give a client an insecure system or its my head ^_^

Edited by botanic

Share this post


Link to post
Share on other sites
weaponx

RunWait("wuauclt /detectnow")

Share this post


Link to post
Share on other sites
Danny35d

Do It Yourselft Service Pack - Read this articule

Download version 5.2

This is a windows update offline, the author used a combination of AutoIt and batch file script. His application download all updates for Win2k, WinXp, Win2k3, Vista, Office2k, OfficeXp, Office2k3 and Office2k7. Then you can burned to a DVD or copy to USB memory stick and install windows updates without the internet.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
botanic

wuauclt /detectnow does not download and install the updates. It only checks for them >.> as for the offline tool i need the latest updates, the whole point is to have a server autoupdate all the latest updates on first boot

Share this post


Link to post
Share on other sites
Melba23

botanic,

Can you not automate the Windows Update app itself using ControlSend, ControlCommand and ControlClick?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Valuater

Seems to me this has been brought up many, many times before.

... did anyone search the topic?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
GEOSoft

Seems to me this has been brought up many, many times before.

... did anyone search the topic?

8)

It's been done before because I have the code. I couldn't find it in Example scripts nor do I remember who wrote it. The only problem I can recall was that it auto-installed all available updates without giving you the option.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
strikey

I would like to have this script to ^_^ hehe seems nice to have on a network with sheep users:p

Share this post


Link to post
Share on other sites
GEOSoft

Here is the code but I still don't remember who wrote it. If anyone knows who it belongs to then please post the information or a link to the original thread that I also can't find.

;
#include <date.au3>

$updateSession = ObjCreate("Microsoft.update.Session")
$updateSearcher = $updateSession.CreateupdateSearcher()

ConsoleWrite("Searching for updates..." & @CRLF)

$searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Software'")

ConsoleWrite("List of applicable items on the machine:")
For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    ConsoleWrite($I + 1 & "> " & $update.Title & @CR)
Next

If $searchResult.Updates.Count = 0 Then
    ConsoleWrite("There are no applicable updates.")
    Exit
EndIf

ConsoleWrite(@CRLF & "Creating collection of updates to download:")
$updatesToDownload = ObjCreate("Microsoft.update.UpdateColl")

For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    ConsoleWrite($I + 1 & "> adding: " & $update.Title & @CR)
    $updatesToDownload.Add($update)
Next

ConsoleWrite(@CRLF & "Downloading updates...")
$downloader = $updateSession.CreateUpdateDownloader()
$downloader.Updates = $updatesToDownload
$downloader.Download()

ConsoleWrite(@CRLF & "List of downloaded updates:")
For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    If $update.IsDownloaded Then
        ConsoleWrite($I + 1 & "> " & $update.Title & @CR)
    EndIf
Next

$updatesToInstall = ObjCreate("Microsoft.update.UpdateColl")

ConsoleWrite(@CRLF & "Creating collection of downloaded updates to install:")
For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    If $update.IsDownloaded = True Then
        ConsoleWrite($I + 1 & "> adding: " & $update.Title & @CR)
        $updatesToInstall.Add($update)
    EndIf
Next

ConsoleWrite(@CRLF & "Installing updates...")
$installer = $updateSession.CreateUpdateInstaller()
$installer.Updates = $updatesToInstall
If $updatesToInstall.Count > 0 Then
    $installationResult = $installer.Install()
   ;Output results of install
    ConsoleWrite("Installation Result: " & $installationResult.ResultCode)
    ConsoleWrite("Listing of updates installed " & "and individual installation results:")
    For $I = 0 To $updatesToInstall.Count - 1
        ConsoleWrite($I + 1 & "> " & $updatesToInstall.Item($I).Title & ": " & $installationResult.GetUpdateResult($I).ResultCode & @CR)
    Next
Else
    ConsoleWrite(@CRLF & "Nothing to install" & @CRLF)
EndIf
;

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
rajeshontheweb
rajeshontheweb
cherdeg

Hi guys..

on http://www.wsus.de (exaclty on http://downloads.wsus.de/updatehf_ver2/updatehf.vbs) one can find the following VB script in the downloads section; I would very like to convert it to AutoIt to be able to integrate it into my works, but had no success yet (because the code created by vaconvert 0.4latest is completely unusable).

The code allows to control windowsupdate and the installation of patches on remote machines, which would be very very useful. I have to manage about 1400 Windows Servers that are only partly members of domains and do not even share a common local group policy. Some of them are allowed to restart freely, others not. I need to be able to control this last group's windows update behavior and make them install patches when I decide it's the right time to. So please help to convert this very cool tool to AutoIt.

The codebox didn't work with the amount of text, so I uploaded the VBS.

Best Regards,

Chris

updatehf.vbs.txt

Edited by cherdeg

Share this post


Link to post
Share on other sites
Tec

Take a look at this vbs. Easy to convert it to Autoit

strComputer = Inputbox("Enter Computername to force updates","Force Windows Updates")
    If strComputer = "" Then WScript.quit
On Error GoTo 0

Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")

strJobfile = "\\"& strComputer & "\admin$\tasks\RunOnce.job"
strPatchScript = "\\"& strComputer & "\c$\patchscript.vbs"

strScript = "Set objSession = CreateObject(" & chr(34) & "Microsoft.Update.Session" & chr(34) & ")" & vbcrlf & _
        "Set AutoUpdate = CreateObject(" & chr(34) & "Microsoft.Update.AutoUpdate" & chr(34) & ")" & vbcrlf & _
        vbcrlf & _
        "Set UpdateSearcher = objSession.CreateUpdateSearcher" & vbcrlf & _
        "Set SearchResult = UpdateSearcher.Search(" & chr(34) & " IsAssigned=1 and IsHidden=0 and IsInstalled=0 and Type='Software'" & chr(34) & ")" & vbcrlf & _
        vbcrlf & _
        "Autoupdate.DetectNow()" & vbcrlf & _
        vbcrlf & _
        "If searchResult.Updates.Count = 0 Then" & vbcrlf & _
        "   WScript.Quit(0)" & vbcrlf & _
        "End If " & vbcrlf & _
        vbcrlf & _
        "Set updatesToDownload = CreateObject(" & chr(34) & "Microsoft.Update.UpdateColl" & chr(34) & ")" & vbcrlf & _      
        "For i = 0 To SearchResult.Updates.Count-1" & vbcrlf & _
        "   Set update = SearchResult.Updates.Item(I) " & vbcrlf & _
        "   If Not update.EulaAccepted Then update.AcceptEula " & vbcrlf & _
        "   updatesToDownload.Add(update)" & vbcrlf & _
        "Next" & vbcrlf & _ 
        vbcrlf & _
        "Set downloader = objSession.CreateUpdateDownloader()" & vbcrlf & _
        "downloader.Updates = updatesToDownload" & vbcrlf & _
        "downloader.Download()" & vbcrlf & _
        vbcrlf & _
        "Set UpdatesToInstall = CreateObject(" & chr(34) & "Microsoft.Update.UpdateColl" & chr(34) & ")" & vbcrlf & _
        "For I = 0 To searchResult.Updates.Count-1" & vbcrlf & _
        "   set update = searchResult.Updates.Item(I)" & vbcrlf & _
        "   If update.IsDownloaded = true Then" & vbcrlf & _
        "       UpdatesToInstall.Add(update)" & vbcrlf & _
        "   End If" & vbcrlf & _
        "Next" & vbcrlf & _
        vbcrlf & _
        "Set installer = objSession.CreateUpdateInstaller()" & vbcrlf & _
        "installer.Updates = updatesToInstall" & vbcrlf & _
        "installer.Install()" & vbcrlf & _
        vbcrlf & _
        "WScript.Quit(0)"

  ' if the script already exists, delete it
  If fso.FileExists(strPatchScript) Then fso.DeleteFile strPatchScript, true

' create the vbscript
Set TextStream = fso.CreateTextFile(strPatchScript)

' write the vbscript file
TextStream.Write(strScript) 
TextStream.Close
    
If fso.FileExists(strJobFile) Then fso.DeleteFile strJobFile, True
    
If (Err.Number <> 0) Then 
    MsgBox "Failed to delete old job " & Err.Description, vbcritical + vbokonly,strComputer
    WScript.Quit
End If 
    
    RemoteDateTime()

' Add minutes
strNewTime = DateAdd("n", 2, time)

' setup the scheduled task on the remote machine
'strUserName  = wshShell.ExpandEnvironmentStrings("%USERDOMAIN%\%USERNAME%")
strUserName = strComputer & "\Administrator"
strpassword = GetPassword("Please enter " & strComputer & "\Administrator password to create the scheduled task:")
strExe = "\\" & strComputer & "\admin$\system32\wscript.exe c:\patchscript.vbs "
strNewTime = cstr(FormatDateTime(strNewTime, vbShortTime))& ":00"
strCommand = "SCHTASKS /s " & strComputer & " /Create /SC EINMAL /TN WindowsUpdate /TR " & chr(34) & strExe & chr(34) &_
    " /ST "& strNewTime & " /RU " & chr(34) & strUserName & chr(34) & " /RP " & chr(34) & strpassword & chr(34)

'Set TxtStream = fso.CreateTextFile("c:\test.txt")
'TextStream.Write(strCommand) 
'TextStream.Close

' run the scheduled task
retval = WshShell.Run(strCommand, 0, True)

  If retval = 0 Then
    MsgBox "The patch task was successfully created to start at " & strNewTime
  Else
    strMessage ="There were problems creating the patch task. " & Err.Description
    MsgBox strMessage, vbCritical + vbOKOnly, "Fatal Error"
  End If

WScript.Quit(0)


Sub RemoteDateTime()
    On Error Resume Next
    Dim objWMI, colItems, objItem
    Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
        If (Err.Number <> 0) Then
            MsgBox "WMI Failure " & err.Description, vbcritical + vbokonly,strComputer
        Exit Sub
    End If 
    Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_Localtime",,48)
    For Each objItem In colItems
        strRmtDate = objItem.Year & "-" & padNum(objItem.Month) & "-" & padnum(objItem.Day)
        strRmtTime = objItem.Hour & ":" & padNum(objItem.Minute) & ":" & padnum(objItem.Second)
    Next
End Sub

Function MinutesDiff(theTime)
  MinutesDiff = DateDiff("n", theTime, now)
End Function
 
Function WMIDateStringToDate(utcDate)
    WMIDateStringToDate = CDate(Mid(utcDate, 5, 2) & "/" & _
    Mid(utcDate, 7, 2) & "/" & _
    Left(utcDate, 4) & " " & _
    Mid(utcDate, 9, 2) & ":" & _
    Mid(utcDate, 11, 2) & ":" & _
    Mid(utcDate, 13, 2))
End Function

Function Sessiontime()
    On Error Resume Next 
    Dim objWMI, ColSessions, objSession, strLogonTime
    Dim iElapsedTime, iHours, iMinutes
    Set objWMI = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
    Set ColSessions = objWMI.ExecQuery("Select * from Win32_LogonSession where LogonType=2",,48)
    strLogonTime  = 0
    If (Err.Number <> 0) Then
        MsgBox "Getting session information from "& strComputer & " failed. "  & Err.Description, vbCritical  + vbOKOnly,"Success"
        Exit Function  
    End If  

    For Each objSession In ColSessions
       If WMIDateStringToDate(objSession.StartTime) > strLogonTime Then 
          strLogonTime = WMIDateStringToDate(objSession.StartTime)
       End If 
    Next
        
    iElapsedTime = MinutesDiff(strLogonTime)
    iHours = int(iElapsedTime /60)
    iMinutes = iElapsedTime Mod 60
    Sessiontime = iHours & " Hours " & iMinutes & " minutes."
End Function

Function GetPassword(myPrompt)
    Dim objIE
    Set objIE = CreateObject( "InternetExplorer.Application" )
    objIE.Navigate "about:blank"
    do until objIE.readyState = 4 : wscript.sleep 10 : loop  
    objIE.document.Title = "Password"
    objIE.ToolBar       = False
    objIE.Resizable   = False
    objIE.StatusBar   = False
    objIE.Width       = 300
    objIE.Height         = 180

    With objIE.document.Parentwindow.Screen
        objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
        objIE.Top  = (.Availheight - objIE.Height) \ 2
    End With
  
    objIE.document.Body.InnerHTML = "<DIV align='center'><P>" & myPrompt _
                                  & "</P>" & vbCrLf _
                                  & "<P><INPUT TYPE='password' SIZE= '20'" _
                                  & "ID='Password'></P>" & vbCrLf _
                                  & "<P><INPUT TYPE='hidden' ID='OK'" _
                                  & "NAME='OK' VALUE='0'>" _
                                  & "<INPUT TYPE='submit' VALUE='OK'" _
                                  & "onclick='vb script:OK.Value=1'></P></DIV>"
    objIE.Visible = True

    Do While objIE.document.All.OK.Value = 0
        WScript.Sleep 200
    Loop

    GetPassword = objIE.document.All.Password.Value

    objIE.Quit
    Set objIE = Nothing
End Function

Client Script that the script create. Dont need it. Only for overview

Set objSession = CreateObject("Microsoft.Update.Session")
Set AutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")

Set UpdateSearcher = objSession.CreateUpdateSearcher
Set SearchResult = UpdateSearcher.Search(" IsAssigned=1 and IsHidden=0 and IsInstalled=0 and Type='Software'")

Autoupdate.DetectNow()

If searchResult.Updates.Count = 0 Then
    WScript.Quit(0)
End If 

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For i = 0 To SearchResult.Updates.Count-1
    Set update = SearchResult.Updates.Item(I) 
    If Not update.EulaAccepted Then update.AcceptEula 
    updatesToDownload.Add(update)
Next

Set downloader = objSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()

Set UpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 To searchResult.Updates.Count-1
    set update = searchResult.Updates.Item(I)
    If update.IsDownloaded = true Then
        UpdatesToInstall.Add(update)
    End If
Next

Set installer = objSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
installer.Install()

WScript.Quit(0)

English clients need to change this:

strCommand = "SCHTASKS /s " & strComputer & " /Create /SC EINMAL

to

strCommand = "SCHTASKS /s " & strComputer & " /Create /SC ONES

Look at schtasks /create /help

Share this post


Link to post
Share on other sites
holebergers

To run Windows Update Program. In SciTE Script Editor, type

Run("%windir%\system32\wuapp.exe")

Then type:

MouseMove(x,y)
MouseClick($MOUSE_CLICK_LEFT)
Sleep(30000)

I put a delay of 30 secs for update checking. You gays may change it according to your convenience.

Here, x and y are the coordinates of Check for Updates button. I hope you all will be able to get the coordinates using screenshot. If its any help for me its 677,241 when maximized. It may differ for you guys.

Again type:

MouseMove(x,y)
MouseClick($MOUSE_CLICK_LEFT)
Sleep(30000)

Here, x and y are the coordinates of Install Now button. I hope you all will be able to get the coordinates using screenshot. If its any help for me its 679,248. It may differ for you guys.

There its done.

Please not that I made the snap code for Windows 7. Also that I am a newbie and tested the program only once.

Share this post


Link to post
Share on other sites
JLogan3o13

@holebergers, did you miss that this thread was 7 years old? Please don't necro old posts, especially when adding nothing to the conversation beyond a very unreliable MouseClick hack that even you admit to not having tested well.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×