mastrboy Posted March 4, 2008 Posted March 4, 2008 is it possible to convert this vbs script to autoit? If yes, how will i approach it? expandcollapse popupSet updateSession = CreateObject("Microsoft.Update.Session") Set updateSearcher = updateSession.CreateupdateSearcher() WScript.Echo "Searching for updates..." & vbCRLF Set searchResult = _ updateSearcher.Search("IsInstalled=0 and Type='Software'") WScript.Echo "List of applicable items on the machine:" For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) WScript.Echo I + 1 & "> " & update.Title Next If searchResult.Updates.Count = 0 Then WScript.Echo "There are no applicable updates." WScript.Quit End If WScript.Echo vbCRLF & "Creating collection of updates to download:" Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl") For I = 0 to searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) WScript.Echo I + 1 & "> adding: " & update.Title updatesToDownload.Add(update) Next WScript.Echo vbCRLF & "Downloading updates..." Set downloader = updateSession.CreateUpdateDownloader() downloader.Updates = updatesToDownload downloader.Download() WScript.Echo vbCRLF & "List of downloaded updates:" For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) If update.IsDownloaded Then WScript.Echo I + 1 & "> " & update.Title End If Next Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl") WScript.Echo vbCRLF & "Creating collection of downloaded updates to install:" For I = 0 To searchResult.Updates.Count-1 set update = searchResult.Updates.Item(I) If update.IsDownloaded = true Then WScript.Echo I + 1 & "> adding: " & update.Title updatesToInstall.Add(update) End If Next WScript.Echo vbCRLF & "Installing updates..." Set installer = updateSession.CreateUpdateInstaller() installer.Updates = updatesToInstall Set installationResult = installer.Install() 'Output results of install WScript.Echo "Installation Result: " & installationResult.ResultCode WScript.Echo "Listing of updates installed " & "and individual installation results:" For I = 0 to updatesToInstall.Count - 1 WScript.Echo I + 1 & "> " & _ updatesToInstall.Item(i).Title & _ ": " & installationResult.GetUpdateResult(i).ResultCode Next -
weaponx Posted March 4, 2008 Posted March 4, 2008 (edited) Change all "Set" to "Dim" Change all "CreateObject" to "ObjCreate" Change all "WScript.Echo" to "ConsoleWrite" Change all "WScript.Quit" to "Exit" Change all "End If" to "EndIf" Add dollar sign in front of all variables and objects Edited March 4, 2008 by weaponx
ptrex Posted March 4, 2008 Posted March 4, 2008 @all Maybe this can get you going expandcollapse popup#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 = 1 Then ConsoleWrite ($I + 1 & "> adding: " & $update.Title & @CR) $updatesToInstall.Add($update) EndIf Next ConsoleWrite (@CRLF & "Installing updates...") $installer = $updateSession.CreateUpdateInstaller() $installer.Updates = $updatesToInstall $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 regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
mastrboy Posted March 5, 2008 Author Posted March 5, 2008 thanks guys, really helped me out.. i modified it for my needs, now it only selects critical updates and writes to a log file. expandcollapse popup#include <file.au3> $logfile = @WindowsDir&"\sysprep-update.log" ; MS Ref: http://msdn2.microsoft.com/en-us/library/aa387291(VS.85).aspx $updateSession = ObjCreate("Microsoft.update.Session") $updateSearcher = $updateSession.CreateupdateSearcher() ; Searching for updates... _FileWriteLog($logfile,"Searching for updates") $searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Software'") ; 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 ; There are no applicable updates _FileWriteLog($logfile,"There are no applicable updates, exited script") Exit EndIf ; Creating collection of updates to download: $updatesToDownload = ObjCreate("Microsoft.update.UpdateColl") For $I = 0 to $searchResult.Updates.Count-1 $update = $searchResult.Updates.Item($I) ; Only add security updates to download list If $update.MsrcSeverity Then $updatesToDownload.Add($update) _FileWriteLog($logfile,"Adding update: "&$update.Title) ; ConsoleWrite ($I + 1 & "> adding: " & $update.Title & @CR) EndIf Next If $updatesToDownload.Count = 0 Then _FileWriteLog($logfile,"There are no applicable updates, exited script") ; No security updates, so exit Exit EndIf ; Downloading updates... _FileWriteLog($logfile,"Downloading updates") $downloader = $updateSession.CreateUpdateDownloader() $downloader.Updates = $updatesToDownload $downloader.Download() ; List of downloaded updates: For $I = 0 To $searchResult.Updates.Count-1 $update = $searchResult.Updates.Item($I) If $update.IsDownloaded Then _FileWriteLog($logfile,"Downloaded update: "&$update.Title) ;ConsoleWrite ($I + 1 & "> " & $update.Title & @CR) EndIf Next $updatesToInstall = ObjCreate("Microsoft.update.UpdateColl") ; Creating collection of downloaded updates to install: _FileWriteLog($logfile,"Creating collection of downloaded updates to install") For $I = 0 To $searchResult.Updates.Count-1 $update = $searchResult.Updates.Item($I) If $update.IsDownloaded Then ;ConsoleWrite ($I + 1 & "> adding: " & $update.Title & @CR) _FileWriteLog($logfile,"Installing update: "&$update.Title) $updatesToInstall.Add($update) EndIf Next ; Installing updates... $installer = $updateSession.CreateUpdateInstaller() $installer.Updates = $updatesToInstall $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) _FileWriteLog($logfile,"Installed update: "&$updatesToInstall.Item($I).Title & " : " & $installationResult.GetUpdateResult($I).ResultCode) Next -
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now