Bypassing windows during processes

Welcome Forums General PowerShell Q&A Bypassing windows during processes

Viewing 1 reply thread
  • Author
    Posts
    • #28647
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      I am almost finished with my script that gets rid of certain windows updates and hides them but after an unistall it asks if you want to restart I cannot seem to get my

      $wshell = New-Object -ComObject wscript.shell;
      $wshell.AppActivate('Windows Update Standalone Installer')
      Sleep 2
      $wshell.SendKeys('~')

      could I put two keys one to tab and one to enter? maybe an IF statement to say if true for unistalling then hit these two keys? I am newer to this so I don't have advanced skills for powershell. Thanks!

    • #28650
      Participant
      Topics: 10
      Replies: 1284
      Points: 1,084
      Helping Hand
      Rank: Community Hero

      If you are using SendKeys as a solution, it is most likely the wrong solution. In vbScript forums, I used to continually talk folks out of using it because there is no way to ensure the script is doing what it's supposed to. You're sending commands blindly to the screen and assuming that the Window you expect opened and is active when you are sending commands.

      With that said, there is a programmatic way to manage hiding windows updates. Take a look at this article: http://www.powershellmagazine.com/2014/03/19/how-to-view-and-restore-hidden-windows-updates-with-powershell/

      I used to create the below that hides the annoying Windows 7 language packs in my labs:

      Function Get-WindowsUpdate {
       
          [Cmdletbinding()]
          Param()
       
          Process {
              try {
                  Write-Verbose "Getting Windows Update"
                  $Session = New-Object -ComObject Microsoft.Update.Session            
                  $Searcher = $Session.CreateUpdateSearcher()            
                  $Criteria = "IsInstalled=0 and DeploymentAction='Installation' or IsPresent=1 and DeploymentAction='Uninstallation' or IsInstalled=1 and DeploymentAction='Installation' and RebootRequired=1 or IsInstalled=0 and DeploymentAction='Uninstallation' and RebootRequired=1"           
                  $SearchResult = $Searcher.Search($Criteria)           
                  $SearchResult.Updates
              } catch {
                  Write-Warning -Message "Failed to query Windows Update because $($_.Exception.Message)"
              }
          }
      }
       
      Function Show-WindowsUpdate {
          Get-WindowsUpdate |
          Select Title,isHidden,
              @{l='Size (MB)';e={'{0:N2}' -f ($_.MaxDownloadSize/1MB)}},
              @{l='Published';e={$_.LastDeploymentChangeTime}} |
          Sort -Property Published
      }
      
      Function Set-WindowsHiddenUpdate {
       
          [Cmdletbinding()]
       
          Param(
              [Parameter(ValueFromPipeline=$true,Mandatory=$true)]
              [System.__ComObject[]]$Update,
       
              [Parameter(Mandatory=$true)]
              [boolean]$Hide
          )
       
          Process {
              $Update | ForEach-Object -Process {
                  if (($_.pstypenames)[0] -eq 'System.__ComObject#{c1c2f21a-d2f4-4902-b5c6-8a081c19a890}') {
                      try {
                          $_.isHidden = $Hide
                          Write-Verbose -Message "Dealing with update $($_.Title)"
                      } catch {
                          Write-Warning -Message "Failed to perform action because $($_.Exception.Message)"
                      }
                  } else {
                      Write-Warning -Message "Ignoring object submitted"
                  }
              }
          }
      }
      
      $updates = Get-WindowsUpdate
      $updates | Where{$_.Title -like "*language*" -and $_.IsHidden -eq $false} | Set-WindowsHiddenUpdate -Hide $True
      
Viewing 1 reply thread
  • The topic ‘Bypassing windows during processes’ is closed to new replies.