简体   繁体   中英

How to stop a service in Windows 10 Pro 1903 with powershell

In Powershell I would like to stop a service:

Stop-Service -Name "StateRepository" -Force 

The service won't stop. It doesn't make any difference how long I wait. I'm signed on with the user Administrator in Windows 10 Pro 1903. I don't get any errors. When I look in services.msc the service is not stopped.

If Stop-Service -Force isn't working, I'm not sure what's going on here. However, you can use WMI/CIM to get the current PID of the service and kill it that way (note that this can be an unsafe operation):

$service = Get-CimInstance Win32_Service | Where-Object { $_.Name -eq "StateRepository" } | Select -First 1 Name, ProcessId
Write-Warning "Killing process $($service.ProcessId) for service $($service.Name)"
Stop-Process -Force $service.ProcessId

This said, it's always better to look into why a service won't stop, as this technique would be more of a last resort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM