Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Batch Script


  • Please log in to reply
2 replies to this topic

#1
usman

usman
  • Member
  • 1 posts
  • OS:none specified
  • Country: Country Flag
Hi

I need a batch script that will install updates of windows 7 professional 32 bit and 64 bit .Please help me as early as possible.

Thanks in advance


How to remove advertisement from MSFN

#2
uid0

uid0

    Advanced Member

  • Member
  • PipPipPip
  • 357 posts
@echo off

setlocal enableextensions enabledelayedexpansion

cd /d "%~dp0"

for /f "usebackq delims=" %%a in (`dir /a-d /od /b *`) do (

	set file=%%a

	if not "!file!" == "%~n0%~x0" (

		echo !file!

		if /I "!file:~-4!" == ".msu" (

			start /w wusa %%a /quiet /norestart

		) else if /I "!file!" == "rvkroots.exe" (

			start /w %%a /q

		) else 	if /I "!file:~-4!" == ".exe" (

			start /w %%a /q /n /z

		) else (

			echo Not sure what to do with "!file!"

		)

	)

)

pause

Edited by Tripredacus, 05 December 2012 - 08:39 AM.


#3
Yzöwl

Yzöwl

    Wise Owl

  • Member
  • PipPipPipPipPipPipPipPipPip
  • 4,532 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Since you're using Windows 7 I'd suggest using powershell for this task.

If your .msu files are all in one location then this powershell line may be sufficient for your needs.
ls *.msu | %{start -wait $_ -argumentlist '/quiet /norestart'}
If they're in individual directories within the working directory then use recurse
ls *.msu -recurse | %{start -wait $_ -argumentlist '/quiet /norestart'}
In either case run as Administrator

FYI There is also a Powershell Module which may be of interest, see here.

Footnote
If you want something a little more advanced, the following code taken from Technet's discussion group will both download and update for you!
<#
	.SYNOPSIS
		Get and optionally install Windows Updates
	.DESCRIPTION
		This script will get all available udpates for the computer it is run on.
		It will then optionally install those updates, provided they do not require
		user input.

		This script was based off the original vbs that appeared on the MSDN site.
		Please see the Related Links section for the URL.

		Without any parameters the script will return the title of each update that
		is currently available.
	.PARAMETER Install
		When present the script will download and install each update. If the EulaAccept
		param has not been passed, only updates that don't have a Eula will be applied.
	.PARAMETER EulaAccept
		When present will allow the script to download and install all updates that are
		currently available.
	.EXAMPLE
		.\Get-WindowsUpdates.ps1

		There are no applicable updates

		Description
		-----------
		This system is currently patched and up to date.
		.NOTES
		ScriptName : Get-WindowsUpdates.ps1
		Created By : jspatton
		Date Coded : 08/29/2012 13:06:31
		ScriptName is used to register events for this script

		ErrorCodes
		100 = Success
		101 = Error
		102 = Warning
		104 = Information

	.LINK
		https://code.google.com/p/mod-posh/wiki/Production/Get-WindowsUpdates.ps1
	.LINK
		http://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx
#>
[CmdletBinding()]
Param
	(
	[switch]$Install,
	[switch]$EulaAccept
	)
Begin
	{
		$ScriptName = $MyInvocation.MyCommand.ToString()
		$ScriptPath = $MyInvocation.MyCommand.Path
		$Username = $env:USERDOMAIN + "\" + $env:USERNAME

		New-EventLog -Source $ScriptName -LogName 'Windows Powershell' -ErrorAction SilentlyContinue

		$Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nStarted: " + (Get-Date).toString()
		Write-EventLog -LogName 'Windows Powershell' -Source $ScriptName -EventID "104" -EntryType "Information" -Message $Message

		#	Dotsource in the functions you need.

		$UpdateSession = New-Object -ComObject 'Microsoft.Update.Session'
		$UpdateSession.ClientApplicationID = 'MSDN PowerShell Sample'
	}
Process
	{
		$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
		$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")

		if ($Install)
		{
			Write-Verbose 'Creating a collection of updates to download:'
			$UpdatesToDownload = New-Object -ComObject 'Microsoft.Update.UpdateColl'
			foreach ($Update in $SearchResult.Updates)
			{
				[bool]$addThisUpdate = $false
				if ($Update.InstallationBehavior.CanRequestUserInput)
				{
					Write-Verbose "> Skipping: $($Update.Title) because it requires user input"
				}
				else
				{
					if (!($Update.EulaAccepted))
					{
						Write-Verbose "> Note: $($Update.Title) has a license agreement that must be accepted:"
						if ($EulaAccept)
						{
							$Update.AcceptEula()
							[bool]$addThisUpdate = $true
						}
						else
						{
							Write-Verbose "> Skipping: $($Update.Title) because the license agreement was declined"
						}
					}
					else
					{
						[bool]$addThisUpdate = $true
					}
				}
				if ([bool]$addThisUpdate)
				{
					Write-Verbose "Adding: $($Update.Title)"
					$UpdatesToDownload.Add($Update) |Out-Null
				}
			}
			if ($UpdatesToDownload.Count -eq 0)
			{
				Write-Verbose 'All applicable updates were skipped.'
				break
			}

			Write-Verbose 'Downloading updates...'
			$Downloader = $UpdateSession.CreateUpdateDownloader()
			$Downloader.Updates = $UpdatesToDownload
			$Downloader.Download()

			$UpdatesToInstall = New-Object -ComObject 'Microsoft.Update.UpdateColl'

			[bool]$rebootMayBeRequired = $false
			Write-Verbose 'Successfully downloaded updates:'

			foreach ($Update in $SearchResult.Updates)
			{
				if ($Update.IsDownloaded)
				{
					Write-Verbose "> $($Update.Title)"
					$UpdatesToInstall.Add($Update) |Out-Null

					if ($Update.InstallationBehavior.RebootBehavior -gt 0)
					{
						[bool]$rebootMayBeRequired = $true
					}
				}
			}
				if ($UpdatesToInstall.Count -eq 0)
				{
					Write-Verbose 'No updates were succsesfully downloaded'
				}
				if ($rebootMayBeRequired)
				{
					Write-Verbose 'These updates may require a reboot'
				}
				Write-Verbose 'Installing updates...'

				$Installer = $UpdateSession.CreateUpdateInstaller()
				$Installer.Updates = $UpdatesToInstall
				$InstallationResult = $Installer.Install()

				Write-Verbose "Installation Result: $($InstallationResult.ResultCode)"
				Write-Verbose "Reboot Required: $($InstallationResult.RebootRequired)"
				Write-Verbose 'Listing of updates installed and individual installation results'

				for($i=0; $i -lt $UpdatesToInstall.Count; $i++)
				{
					New-Object -TypeName PSObject -Property @{
					Title = $UpdatesToInstall.Item($i).Title
					Result = $InstallationResult.GetUpdateResult($i).ResultCode
				}
			}
		}
		else
		{
			if ($SearchResult.Updates.Count -ne 0)
			{
				$SearchResult.Updates |Select-Object -Property Title, Description, SupportUrl, UninstallationNotes, RebootRequired |Format-List
			}
			else
			{
				Write-Host 'There are no applicable updates'
			}
		}
	}

End
	{
		$Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nFinished: " + (Get-Date).toString()
		Write-EventLog -LogName 'Windows Powershell' -Source $ScriptName -EventID "104" -EntryType "Information" -Message $Message
	}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN