Skip to content

Instantly share code, notes, and snippets.

@thaddeusc1
Last active May 26, 2023 13:52
Show Gist options
  • Save thaddeusc1/676cecb593b6308de1818b579c10171e to your computer and use it in GitHub Desktop.
Save thaddeusc1/676cecb593b6308de1818b579c10171e to your computer and use it in GitHub Desktop.
Stop non-essential Windows services and processes before performing critical software installation
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
$serviceNames = @(
"AcrSch2Svc", # Acronis Scheduler2 Service (depends on RpcSs)
"afcdpsrv", # Acronis Nonstop Backup Service
"mmsminisrv", # Acronis Managed Machine Service Mini (depends on aakore)
"EABackgroundService", # Electronic Arts
"DSAService", # Intel Driver & Support Assistant
"Tib Mounter Service", # Acronis (depends on RpcSs)
"CAMService", # NZXT
"MPService", # CoolerMaster MasterPlus Technology Service
"FuryContorller_Service", # Kingston
"GamingServicesNet", # Microsoft (depends on StateRepository)
"GamingServices", # Microsoft (depends on StateRepository)
"XTU3SERVICE", # Intel [XTU] Overclocking Component Service
# Services that other services depend upon should be positioned at the end of the list:
"aakore" # Acronis Agent Core Service
)
$processNames = @(
"TrueImageMonitor", # Acronis
"tib_mounter_monitor", # Acronis
"HID", # Intel ARC RGB controller
"LogiOptions",
"LogiOptionsMgr",
"LogiOverlay",
"GameBarFTServer", # Microsoft
"GameBar" # Microsoft
)
# Serialize service shutdown to ensure services dependant upon other services are stopped before attempting to stop their depencencies.
foreach ($sName in $serviceNames)
{
$sStatus = "Failure: Stop-Service invocation failed."
try
{
Stop-Service -Name $sName -ErrorAction Stop
$sStatus = "Stopped."
}
catch
{
$sStatus = "Error: " + $_.Exception.Message
}
finally
{
#TODO: Visual indicator when printing status.
echo "Service ${sName}: $sStatus"
}
}
foreach ($pName in $processNames)
{
$pStatus="Failure: Stop-Process invocation failed."
try
{
Stop-Process -Name $pName -ErrorAction Stop
$pStatus="Stopped."
}
catch [System.SystemException]
{
if( $_.Exception.Message.Contains("Cannot find a process with the name") )
{
$pStatus = "Not running."
}
else
{
$pStatus = "Error: " + $_.Exception.Message
}
}
catch
{
$pStatus = "Error: " + $_.Exception.Message
}
finally
{
#TODO: Visual indicator when printing status.
echo "Process ${pName}: $pStatus"
}
}
@thaddeusc1
Copy link
Author

Notes

This script needs to be run with admin privledges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment