특정 업데이트 검색, 다운로드 및 설치
이 항목의 스크립팅 샘플에서는 Windows 업데이트 에이전트(WUA)를 사용하여 특정 업데이트를 검색, 다운로드 및 설치하는 방법을 보여 줍니다. 업데이트는 제목으로 지정할 수 있습니다.
샘플은 특정 소프트웨어 업데이트를 검색하고, 업데이트를 다운로드한 다음, 업데이트를 설치합니다. 예를 들어, 사용자는 이 방법을 사용하여 컴퓨터에 중요 보안 업데이트가 설치되어 있는지 여부를 확인할 수 있습니다. 업데이트가 설치되지 않은 경우 사용자는 업데이트를 다운로드하여 설치되도록 할 수 있습니다. 또한 사용자는 설치 상태 대한 알림도 받을 수 있습니다.
샘플 업데이트는 IUpdate의 Title 속성에서 업데이트 제목으로 확인할 수 있습니다. 이 샘플에서 제안하는 업데이트의 제목은 "Windows 권한 관리 클라이언트 1.0용 업데이트"입니다.
참고 항목
특정 애플리케이션에 적용되는 모든 업데이트를 검색, 다운로드 및 설치하는 방법에 대한 자세한 내용은 업데이트 검색, 다운로드 및 설치를 참조하세요.
이 샘플을 실행하기 전에 다음 사항에 유의하세요.
- WUA가 컴퓨터에 설치되어 있어야 합니다. 설치된 WUA의 버전을 확인하는 방법에 대한 자세한 내용은 WUA의 현재 버전 확인를 참조하세요.
- 샘플은 자체 사용자 인터페이스를 제공하지 않습니다. 업데이트에서 다시 시작해야 하는 경우 WUA는 사용자에게 컴퓨터를 다시 시작하라는 메시지를 표시합니다.
- 샘플은 WUA에서만 업데이트를 다운로드할 수 있습니다. 소프트웨어 업데이트 서비스(SUS) 1.0 서버에서는 업데이트를 다운로드할 수 없습니다.
- 이 샘플을 실행하려면 Windows 스크립트 호스트(WSH)가 필요합니다. WSH에 대한 자세한 내용은 플랫폼 소프트웨어 개발 키트(SDK)의 WSH 섹션을 참조하세요. 샘플이 파일 이름이 WUA_SpecificUpdate.vbs인 파일에 복사된 경우 명령 프롬프트 창을 열고 cscript WUA_SpecificUpdate.vbs 명령을 입력하여 실행할 수 있습니다.
참고 항목
검색을 수행할 때 일반적인 메모리 사용량보다 메모리 사용량이 높을 수 있습니다. 검색 프로세스에 충분한 메모리 리소스를 할당하기 위해 시스템을 필요한 대로 조정하는 것이 좋습니다. 여기에는 추가 프로세서 구성 및 페이지 파일 수정이 포함될 수 있습니다. 적절한 메모리 할당을 보장하면 검색을 효율적이고 효과적으로 완료하는 데 도움이 됩니다.
예시
Important
이 스크립트는 Windows 업데이트 에이전트 API의 사용을 보여주며, 개발자가 이러한 API를 사용하여 문제를 해결하는 방법의 예를 제공합니다. 이 스크립트는 프로덕션 코드로 사용되지 않으며, 스크립트 자체는 Microsoft에서 지원되지 않습니다(기본 Windows 업데이트 에이전트 API는 지원됨).
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "Sample Script"
'Get update title to search for
WScript.Echo "Enter the title of the update: " & _
"(for example, Update for Windows Rights Management client 1.0)"
updateTitle = WScript.StdIn.Readline
WScript.Echo vbCRLF & "Searching for: " & updateTitle & "..."
Set updateSearcher = updateSession.CreateupdateSearcher()
'Search for all software updates, already installed and not installed
Set searchResult = _
updateSearcher.Search("Type='Software'")
Set updateToInstall = CreateObject("Microsoft.Update.UpdateColl")
updateIsApplicable = False
'Cycle through search results to look for the update title
For i = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
If UCase(update.Title) = UCase(updateTitle) Then
'Update in list of applicable updates
'Determine if it is already installed or not
If update.IsInstalled = False Then
WScript.Echo vbCRLF & _
"Result: Update applicable, not installed."
updateIsApplicable = True
updateToInstall.Add(update)
Else
'Update is installed so notify user and quit
WScript.Echo vbCRLF & _
"Result: Update applicable, already installed."
updateIsApplicable = True
WScript.Quit
End If
End If
Next
If updateIsApplicable = False Then
WScript.Echo "Result: Update is not applicable to this machine."
WScript.Quit
End If
WScript.Echo vbCRLF & "Would you like to install now? (Y/N)"
stdInput = WScript.StdIn.Readline
If (strInput = "N" or strInput = "n") Then
WScript.Quit
ElseIf (stdInput = "Y" OR stdInput = "y") Then
'Download update
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updateToInstall
WScript.Echo vbCRLF & "Downloading..."
Set downloadResult = downloader.Download()
WScript.Echo "Download Result: " & downloadResult.ResultCode
'Install Update
Set installer = updateSession.CreateUpdateInstaller()
WScript.Echo vbCRLF & "Installing..."
installer.Updates = updateToInstall
Set installationResult = installer.Install()
'Output the result of the installation
WScript.Echo "Installation Result: " & _
installationResult.ResultCode
WScript.Echo "Reboot Required: " & _
installationResult.RebootRequired
End If