Looking for a process to wait for after Office Updates are done.

Rick Someone 411 Reputation points
2021-02-22T22:58:52.857+00:00

I have a PS to enable automatic updates. I have a variable to OfficeC2RClient.exe I have a variable for args, "/update user display level=true" then, Start-Process (both variables). This kicks off Office upgrades which is what we want. But since we don't know exactly when it completes (no notification this way), I want to Start-Process winward.exe The strange thing is, the very first thing that happens is Word launches, then the updates start, then Word runs again after. I can't figure out why Word runs as the very first step in this PS. cd HKLM:\ Set-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\16.0\common\OfficeUpdates" -Name EnableAutomaticUpdates -Value 1 -Force $UpdateEXE = "C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe" $UpdateArguements = "/update user displaylevel=true" Start-Process $UpdateEXE $UpdateArguements Start-Process winword.exe

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,621 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 35,416 Reputation points
    2021-02-23T00:08:52.79+00:00

    Don't use start-process. Call the .exe's directly and test the lastexitcode.

     $runme = 'c:\windows\system32\whoami.exe'
     $parm = '/user'
     & $runme $parm 
     $LASTEXITCODE
    
     $parm = '/bad-argument'
     & $runme  $parm
     $LASTEXITCODE
    
    0 comments No comments

  2. Ian Xue 39,286 Reputation points Microsoft Vendor
    2021-02-23T07:26:43.287+00:00

    Hi,

    There's no need to run word. To wait for a process and its descendants to complete you can use the -Wait parameter. If you want to get the exit time you can add the -PassThru parameter to generate outputs.

    $updateprocess = Start-Process $UpdateEXE $UpdateArguements -Wait -PassThru  
    $updateprocess.ExitTime  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.