Simple Commands for Managing Windows Services
Learn the basic commands for managing Windows services, from viewing them to force-stopping them.
I
InSkillCoach
· min
Simple Commands for Managing Windows Services
Learn the essential commands for managing Windows services, whether through PowerShell or the Command Prompt.
1. Viewing Services
Listing Services
# Afficher tous les services
Get-Service
# Afficher un service spécifique
Get-Service -Name "Windows Update"
# Afficher les services en cours d'exécution
Get-Service | Where-Object {$_.Status -eq "Running"}
# Afficher les services arrêtés
Get-Service | Where-Object {$_.Status -eq "Stopped"}
Detailed Information
# Afficher les détails d'un service
Get-Service -Name "Windows Update" | Format-List *
# Afficher les dépendances d'un service
Get-Service -Name "Windows Update" -DependentServices
# Afficher les services dont dépend un service
Get-Service -Name "Windows Update" -RequiredServices
2. Managing Services
Starting and Stopping
# Démarrer un service
Start-Service -Name "Windows Update"
# Arrêter un service
Stop-Service -Name "Windows Update"
# Redémarrer un service
Restart-Service -Name "Windows Update"
# Suspendre un service (pause)
Suspend-Service -Name "Windows Update"
# Reprendre un service suspendu
Resume-Service -Name "Windows Update"
Force Stop (equivalent to kill -9)
# Arrêt forcé d'un service
Stop-Process -Name "svchost" -Force
# Arrêt forcé avec confirmation
Stop-Process -Name "svchost" -Force -Confirm
# Arrêt forcé d'un service et de ses processus enfants
Stop-Process -Name "svchost" -Force -IncludeChildProcess
Normal Stop (equivalent to kill -15)
# Arrêt normal d'un service
Stop-Service -Name "Windows Update"
# Arrêt normal avec attente
Stop-Service -Name "Windows Update" -Force
# Arrêt normal avec timeout
$service = Get-Service -Name "Windows Update"
$service.Stop()
Start-Sleep -Seconds 30
if ($service.Status -eq "Running") {
Stop-Process -Name "svchost" -Force
}
3. Configuring Services
Startup Type
# Définir le type de démarrage
Set-Service -Name "Windows Update" -StartupType Automatic
# Types disponibles :
# - Automatic (Démarrage automatique)
# - Manual (Démarrage manuel)
# - Disabled (Désactivé)
# Vérifier le type de démarrage
Get-Service -Name "Windows Update" | Select-Object Name, StartType
Permissions
# Voir les permissions d'un service
Get-Acl -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Windows Update"
# Modifier les permissions
$acl = Get-Acl -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Windows Update"
$rule = New-Object System.Security.AccessControl.ServiceAccessRule(
"Administrateurs",
"FullControl",
"Allow"
)
$acl.SetAccessRule($rule)
Set-Acl -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Windows Update" -AclObject $acl
4. CMD Commands (Command Prompt)
Basic Management
# Démarrer un service
net start "Windows Update"
# Arrêter un service
net stop "Windows Update"
# Voir l'état d'un service
sc query "Windows Update"
# Voir tous les services
sc query state= all
Force Stop
# Arrêt forcé d'un service
taskkill /F /IM svchost.exe
# Arrêt forcé avec confirmation
taskkill /F /IM svchost.exe /T
# Arrêt forcé d'un service spécifique
taskkill /F /FI "SERVICES eq Windows Update"
5. Best Practices
Checking Before Stopping
# Vérifier si un service est critique
function Test-CriticalService {
param (
[string]$ServiceName
)
$criticalServices = @(
"LSASS",
"Winlogon",
"Services",
"RpcSs"
)
if ($criticalServices -contains $ServiceName) {
Write-Warning "Ce service est critique !"
return $true
}
return $false
}
# Exemple d'utilisation
if (-not (Test-CriticalService "Windows Update")) {
Stop-Service -Name "Windows Update"
}
Configuration Backup
# Sauvegarder la configuration d'un service
function Backup-ServiceConfig {
param (
[string]$ServiceName
)
$backupPath = "C:\Backups\Services\$ServiceName_$(Get-Date -Format 'yyyyMMdd').txt"
# Créer le dossier si nécessaire
if (-not (Test-Path "C:\Backups\Services")) {
New-Item -ItemType Directory -Path "C:\Backups\Services"
}
# Sauvegarder la configuration
Get-Service -Name $ServiceName | Format-List * | Out-File $backupPath
return $backupPath
}
Conclusion
Key takeaways:
- Always check whether a service is critical before stopping it
- Prefer a normal stop over a force stop
- Back up the configuration before making changes
- Use the appropriate commands for the context
- Document the changes you make
Essential commands:
Get-Service: List servicesStart-Service: Start a serviceStop-Service: Stop a service normallyStop-Process -Force: Force-stop a serviceSet-Service: Configure a service
About InSkillCoach
Training and technology expert
Coach specializing in advanced technologies and AI, backed by GNeurone Inc.
Certifications:
- AWS Certified Solutions Architect – Professional
- Google Cloud certifications
- Microsoft Certified: DevOps Engineer Expert
- Certified Kubernetes Administrator (CKA)
- CompTIA Security+
1.9k
168
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion