Dell पर स्रोत के रूप में Microsoft अद्यतन का उपयोग कर ऑडियो ड्राइवर स्क्रिप्ट स्थापित करने में विफल

Nov 24 2020

मैं dell लैपटॉप पर realtek ऑडियो ड्राइवर स्थापित करने के लिए कोड नीचे चलाने की कोशिश कर रहा हूँ, लेकिन नीचे त्रुटि हो रही है। क्या लापता ऑडियो ड्राइवर को स्थापित करने या इसे अपडेट करने के लिए सभी मॉडल लैपटॉप के लिए इस स्क्रिप्ट का उपयोग करना संभव है? किसी भी तरह की सहायता का स्वागत किया जाएगा

त्रुटि:

RegistrationState ServiceID                            IsPendingRegistrationWithAU Service           
----------------- ---------                            --------------------------- -------           
                3 7971f918-a847-4430-9279-4a52d1efe18d                       False System.__ComObject
Exception from HRESULT: 0x80240024
+ $Downloader.Download() + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException Installing Drivers... Exception from HRESULT: 0x80240024 + $InstallationResult = $Installer.Install() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException **CODE:** $UpdateSvc = New-Object -ComObject Microsoft.Update.ServiceManager            
$UpdateSvc.AddService2("7971f918-a847-4430-9279-4a52d1efe18d",7,"") $Session = New-Object -ComObject Microsoft.Update.Session           
$Searcher = $Session.CreateUpdateSearcher() 

$Searcher.ServiceID = '7971f918-a847-4430-9279-4a52d1efe18d' $Searcher.SearchScope =  1 # MachineOnly
$Searcher.ServerSelection = 3 # Third Party $Criteria = "IsInstalled=0 and Type='Driver'"
Write-Host('Searching Driver-Updates...') -Fore Green     
$SearchResult = $Searcher.Search($Criteria) $Updates = $SearchResult.Updates | Where-Object { $_.DriverManufacturer -like 'Realtek' }
    
#Show available Drivers...

$Updates | select Title, DriverModel, DriverVerDate, Driverclass, DriverManufacturer | fl #Download the Drivers from Microsoft $UpdatesToDownload = New-Object -Com Microsoft.Update.UpdateColl
$updates | % { $UpdatesToDownload.Add($_) | out-null } Write-Host('Downloading Drivers...') -Fore Green $UpdateSession = New-Object -Com Microsoft.Update.Session
$Downloader = $UpdateSession.CreateUpdateDownloader()
$Downloader.Updates = $UpdatesToDownload
$Downloader.Download() #Check if the Drivers are all downloaded and trigger the Installation $UpdatesToInstall = New-Object -Com Microsoft.Update.UpdateColl
$updates | % { if($_.IsDownloaded) { $UpdatesToInstall.Add($_) | out-null } }

Write-Host('Installing Drivers...')  -Fore Green  
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $UpdatesToInstall
$InstallationResult = $Installer.Install()
if($InstallationResult.RebootRequired) {  
Write-Host('Reboot required! please reboot now..') -Fore Red  
} else { Write-Host('Done..') -Fore Green }  ```

जवाब

Theo Nov 25 2020 at 15:24

कुछ चीजें हैं जो मैं आपके कोड में बदलूंगा।
एक बात के लिए, मुझे लगता है कि आप (अनावश्यक रूप से) Microsoft.Update.UpdateCollदो बार एक नई वस्तु बना रहे हैं । तब आप जाँच नहीं कर रहे हैं कि क्या वास्तव में स्थापित करने के लिए अपडेट हैं, किस बिंदु पर कोड से बाहर निकलना चाहिए।

आपके कोड में ड्राइवर निर्माता के लिए परीक्षण है -like 'Realtek', लेकिन *इसके चारों ओर वाइल्डकार्ड वर्ण ( ) के बिना , यह वैसा ही है -eq 'Realtek'और इस वजह से आप एक जोड़े को याद कर सकते हैं।

# check if the Windows Update service is running
if ((Get-Service -Name wuauserv).Status -ne "Running") { 
    Set-Service -Name wuauserv -StartupType Automatic
    Start-Service -Name wuauserv 
} 
# check if there are updates available
$UpdateSession = New-Object -Com Microsoft.Update.Session $UpdateSearcher = $UpdateSession.CreateUpdateSearcher() Write-Host 'Searching Driver-Updates...' -ForegroundColor Green $SearchResult   = $UpdateSearcher.Search("IsInstalled=0 and Type='Driver' and IsHidden=0") # collect the updates $UpdateCollection = New-Object -Com Microsoft.Update.UpdateColl
$Updates = for ($i = 0; $i -lt $SearchResult.Updates.Count; $i++) { $Update = $SearchResult.Updates.Item($i)
    # we are only interested in RealTek Audio driver updates
    # if you need to add more manufacturers, change the first part in the 'if' to for instance
    # $Update.DriverManufacturer -match 'Realtek|Conexant|Intel' if ($Update.DriverManufacturer -like '*Realtek*' -and
       ($Update.Title -like '*audio*' -or $Update.Description -like '*audio*')) {
        if (-not $Update.EulaAccepted) { $Update.AcceptEula() | Out-Null }
        [void]$UpdateCollection.Add($Update)
        # output a PsCustomObject for display purposes only
        $Update | Select-Object Title, DriverModel, DriverVerDate, Driverclass, DriverManufacturer } } # no updates found; exit the script if ($null -eq $Updates -or $Updates.Count -eq 0) {
     Write-Host 'No Driver-Updates available...' -ForegroundColor Cyan
}
else {
    # Show available driver updates...
    $Updates | Format-List # download the updates Write-Host 'Downloading driver updates...' -ForegroundColor Green $Downloader = $UpdateSession.CreateUpdateDownloader() $Downloader.Updates = $UpdateCollection $Downloader.Priority = 3  # high
    [void]$Downloader.Download() # install the updates Write-Host 'Installing Drivers...' -ForegroundColor Green $Installer = $UpdateSession.CreateUpdateInstaller() # accept all Critical and Security bulletins. $Installer.ForceQuiet = $true $Installer.Updates    = $UpdateCollection $InstallationResult   = $Installer.Install() $ResultCode = $InstallationResult.ResultCode # test if the computer needs rebooting if ($InstallationResult.RebootRequired) {
        Write-Host 'Reboot required! please reboot now..' -ForegroundColor Red
    }
    else {
        Write-Host 'Done..' -ForegroundColor Green
    }
}

# Clean-up COM objects
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($UpdateSession) $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($UpdateSearcher) $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($UpdateCollection) $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($SearchResult) if ($Downloader) { $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Downloader)}
if ($Installer) { $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Installer)}
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()