-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make Register MU timeout #17910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Make Register MU timeout #17910
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a157386
Make Register MU timeout
TravisEz13 e772c36
Update Product.wxs
TravisEz13 47439c9
Update powershell-win-core.csproj
TravisEz13 33bf51a
Rename src/PowerShell.Core.Instrumentation/RegisterMicrosoftUpdate.ps…
TravisEz13 90d88c6
Update src/powershell-win-core/powershell-win-core.csproj
TravisEz13 1915f3e
Update RegisterMicrosoftUpdate.ps1
TravisEz13 ff15527
Update RegisterMicrosoftUpdate.ps1
TravisEz13 65d8114
Update files.wxs
TravisEz13 307bd1c
Update assets/MicrosoftUpdate/RegisterMicrosoftUpdate.ps1
TravisEz13 7f82597
Update assets/MicrosoftUpdate/RegisterMicrosoftUpdate.ps1
TravisEz13 181cc35
Update RegisterMicrosoftUpdate.ps1
TravisEz13 df19034
Update RegisterMicrosoftUpdate.ps1
TravisEz13 21aa4c2
Update RegisterMicrosoftUpdate.ps1
TravisEz13 38377ba
Update RegisterMicrosoftUpdate.ps1
TravisEz13 b262268
Update assets/MicrosoftUpdate/RegisterMicrosoftUpdate.ps1
TravisEz13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| param( | ||
| [ValidateSet('Hang', 'Fail')] | ||
| $TestHook | ||
| ) | ||
|
|
||
| $waitTimeoutSeconds = 300 | ||
| switch ($TestHook) { | ||
| 'Hang' { | ||
| $waitTimeoutSeconds = 10 | ||
| $jobScript = { Start-Sleep -Seconds 600 } | ||
| } | ||
| 'Fail' { | ||
| $jobScript = { throw "This job script should fail" } | ||
| } | ||
| default { | ||
| $jobScript = { | ||
| # This registers Microsoft Update via a predifened GUID with the Windows Update Agent. | ||
| # https://docs.microsoft.com/en-us/windows/win32/wua_sdk/opt-in-to-microsoft-update | ||
|
|
||
| $serviceManager = (New-Object -ComObject Microsoft.Update.ServiceManager) | ||
| $isRegistered = $serviceManager.QueryServiceRegistration('7971f918-a847-4430-9279-4a52d1efe18d').Service.IsRegisteredWithAu | ||
|
|
||
| if (!$isRegistered) { | ||
| Write-Verbose -Verbose "Opting into Microsoft Update as the Autmatic Update Service" | ||
| # 7 is the combination of asfAllowPendingRegistration, asfAllowOnlineRegistration, asfRegisterServiceWithAU | ||
| # AU means Automatic Updates | ||
| $null = $serviceManager.AddService2('7971f918-a847-4430-9279-4a52d1efe18d', 7, '') | ||
| } | ||
| else { | ||
| Write-Verbose -Verbose "Microsoft Update is already registered for Automatic Updates" | ||
| } | ||
|
|
||
| $isRegistered = $serviceManager.QueryServiceRegistration('7971f918-a847-4430-9279-4a52d1efe18d').Service.IsRegisteredWithAu | ||
|
|
||
| # Return if it was successful, which is the opposite of Pending. | ||
| return $isRegistered | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Write-Verbose "Running job script: $jobScript" -Verbose | ||
| $job = Start-ThreadJob -ScriptBlock $jobScript | ||
|
|
||
| Write-Verbose "Waiting on Job for $waitTimeoutSeconds seconds" -Verbose | ||
| $null = Wait-Job -Job $job -Timeout $waitTimeoutSeconds | ||
|
|
||
| if ($job.State -ne 'Running') { | ||
| Write-Verbose "Job finished. State: $($job.State)" -Verbose | ||
| $result = Receive-Job -Job $job -Verbose | ||
| Write-Verbose "Result: $result" -Verbose | ||
| if ($result) { | ||
| Write-Verbose "Registration succeeded" -Verbose | ||
| exit 0 | ||
| } | ||
| else { | ||
| Write-Verbose "Registration failed" -Verbose | ||
| # at the time this was written, the MSI is ignoring the exit code | ||
| exit 1 | ||
| } | ||
| } | ||
| else { | ||
| Write-Verbose "Job timed out" -Verbose | ||
| Write-Verbose "Stopping Job. State: $($job.State)" -Verbose | ||
| Stop-Job -Job $job | ||
| # at the time this was written, the MSI is ignoring the exit code | ||
| exit 258 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.