mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 14:17:22 +00:00
Functions [Stop-SvcWithErrHandling] and [Set-SvcWithErrHandling] have been moved to ImageHelpers.psm1
This commit is contained in:
@@ -16,4 +16,6 @@ Export-ModuleMember -Function @(
|
|||||||
'Install-EXE'
|
'Install-EXE'
|
||||||
'Add-ContentToMarkdown'
|
'Add-ContentToMarkdown'
|
||||||
'Add-SoftwareDetailsToMarkdown'
|
'Add-SoftwareDetailsToMarkdown'
|
||||||
|
'Stop-SvcWithErrHandling'
|
||||||
|
'Set-SvcWithErrHandling'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -81,3 +81,82 @@ function Install-EXE
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Stop-SvcWithErrHandling
|
||||||
|
<#
|
||||||
|
.DESCRIPTION
|
||||||
|
Function for stopping the Windows Service with error handling
|
||||||
|
|
||||||
|
.AUTHOR
|
||||||
|
Andrey Mishechkin v-andmis@microsoft.com
|
||||||
|
|
||||||
|
.PARAMETER -ServiceName
|
||||||
|
The name of stopping service
|
||||||
|
|
||||||
|
.PARAMETER -StopOnError
|
||||||
|
Switch for stopping the script and exit from PowerShell if one service is absent
|
||||||
|
#>
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
|
||||||
|
[Parameter()] [switch] $StopOnError
|
||||||
|
)
|
||||||
|
|
||||||
|
Process {
|
||||||
|
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if (-not $Service) {
|
||||||
|
Write-Warning "[!] Service [$ServiceName] is not found";
|
||||||
|
if($StopOnError) {
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "Try to stop service [$ServiceName]";
|
||||||
|
try {
|
||||||
|
Stop-Service -Name $ServiceName -Force;
|
||||||
|
$Service.WaitForStatus("Stopped", "00:01:00");
|
||||||
|
Write-Host "Service [$ServiceName] has been stopped successfuly";
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "[!] Failed to stop service [$ServiceName] with error:"
|
||||||
|
$_ | Out-String | Write-Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Set-SvcWithErrHandling
|
||||||
|
<#
|
||||||
|
.DESCRIPTION
|
||||||
|
Function for setting the Windows Service parameter with error handling
|
||||||
|
|
||||||
|
.AUTHOR
|
||||||
|
Andrey Mishechkin v-andmis@microsoft.com
|
||||||
|
|
||||||
|
.PARAMETER -ServiceName
|
||||||
|
The name of stopping service
|
||||||
|
|
||||||
|
.PARAMETER -Arguments
|
||||||
|
Hashtable for service arguments
|
||||||
|
#>
|
||||||
|
{
|
||||||
|
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
|
||||||
|
[Parameter(Mandatory)] [hashtable] $Arguments
|
||||||
|
)
|
||||||
|
|
||||||
|
Process {
|
||||||
|
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if (-not $Service) {
|
||||||
|
Write-Warning "[!] Service [$ServiceName] is not found";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Set-Service $ServiceName @Arguments;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "[!] Failed to set service [$ServiceName] arguments with error:"
|
||||||
|
$_ | Out-String | Write-Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,56 +2,8 @@
|
|||||||
## File: Install-Chrome.ps1
|
## File: Install-Chrome.ps1
|
||||||
## Desc: Install Google Chrome
|
## Desc: Install Google Chrome
|
||||||
################################################################################
|
################################################################################
|
||||||
function Stop-SvcWithErrHandling
|
|
||||||
{
|
|
||||||
param (
|
|
||||||
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName
|
|
||||||
)
|
|
||||||
|
|
||||||
Process {
|
Import-Module -Name "D:\GitHub\Akvelon\Forks\virtual-environments\images\win\scripts\ImageHelpers\ImageHelpers.psm1" -Force;
|
||||||
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
|
|
||||||
if (-not $Service) {
|
|
||||||
Write-Error "[!] Service [$ServiceName] is not found";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Host "Try to stop service [$ServiceName]";
|
|
||||||
try {
|
|
||||||
Stop-Service -Name $ServiceName -Force;
|
|
||||||
$Service.WaitForStatus("Stopped", "00:01:00");
|
|
||||||
Write-Host "Service [$ServiceName] has been stopped successfuly";
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-Error "[!] Failed to stop service [$ServiceName] with error:"
|
|
||||||
$_ | Out-String | Write-Error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Set-SvcWithErrHandling
|
|
||||||
{
|
|
||||||
param (
|
|
||||||
[Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName,
|
|
||||||
[Parameter(Mandatory)] [hashtable] $Arguments
|
|
||||||
)
|
|
||||||
|
|
||||||
Process {
|
|
||||||
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
|
|
||||||
if (-not $Service) {
|
|
||||||
Write-Warning "[!] Service [$ServiceName] is not found";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Set-Service $ServiceName @Arguments;
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-Error "[!] Failed to set service [$ServiceName] arguments with error:"
|
|
||||||
$_ | Out-String | Write-Error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Import-Module -Name ImageHelpers -Force;
|
|
||||||
|
|
||||||
$ChromeInstallerFile = "chrome_installer.exe";
|
$ChromeInstallerFile = "chrome_installer.exe";
|
||||||
$ChromeInstallerUri = "https://dl.google.com/chrome/install/375.126/${ChromeInstallerFile}";
|
$ChromeInstallerUri = "https://dl.google.com/chrome/install/375.126/${ChromeInstallerFile}";
|
||||||
@@ -61,7 +13,7 @@ Write-Host "Adding the firewall rule for Google update blocking";
|
|||||||
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe";
|
New-NetFirewallRule -DisplayName "BlockGoogleUpdate" -Direction Outbound -Action Block -Program "C:\Program Files (x86)\Google\Update\GoogleUpdate.exe";
|
||||||
|
|
||||||
$GoogleSvcs = ('gupdate','gupdatem');
|
$GoogleSvcs = ('gupdate','gupdatem');
|
||||||
$GoogleSvcs | Stop-SvcWithErrHandling;
|
$GoogleSvcs | Stop-SvcWithErrHandling -StopOnError;
|
||||||
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"};
|
$GoogleSvcs | Set-SvcWithErrHandling -Arguments @{StartupType = "Disabled"};
|
||||||
|
|
||||||
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update";
|
$regGoogleUpdatePath = "HKLM:\SOFTWARE\Policies\Google\Update";
|
||||||
|
|||||||
Reference in New Issue
Block a user