Sign in to follow this  
Followers 0
mastrboy

vbs to autoit

6 posts in this topic

is it possible to convert this vbs script to autoit?

If yes, how will i approach it?

Set 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

 -

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by weaponx

Share this post


Link to post
Share on other sites

@all

Maybe this can get you going

#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

Share this post


Link to post
Share on other sites

ptrex caved, you lucked out.

Share this post


Link to post
Share on other sites

thanks.. i'll try it out.


 -

Share this post


Link to post
Share on other sites

thanks guys, really helped me out.. i modified it for my needs, now it only selects critical updates and writes to a log file.

#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

 -

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
Sign in to follow this  
Followers 0