我有一个崩溃的网络服务器,我应该能够使用以下命令将其关闭:
net stop https-myWebserver
但是,我收到以下错误(在 Windows 7 64 位上):
服务正在启动或停止。请稍后重试。
我如何强制服务立即停止/退出?我希望避免重新启动服务器。
答案1
您应该能够通过任务管理器将其终止。
Right-click on taskbar -> Start Task Manager
如果您可以在“进程”选项卡下找到它:
Right click and select "End Process"
如果你在“进程”下没有看到它(或者不知道要终止的服务的进程是什么),
在“进程”选项卡上
Check "Show processes from all users" in the lower left
Then "View" menu and choose "Select Columns"
Check "PID" and hit OK
Go to the services tab to find the PID of the service you want to kill
Go back to Processes tab and Right-click -> End Process
答案2
您需要找到该服务的 PID,然后将其终止。
使用此命令查找 PID:
tasklist /FI "services eq https-myWebserver"
一旦您获得了 PID 号码,就可以从任务管理器中终止该进程,或者使用 taskkill。
完整详细信息请见此处:http://www.itprostuff.com/articles/find-pid-service.html
答案3
Mike Robbins 的 Powershell 高级功能博客
function Stop-PendingService {
<#
.SYNOPSIS
Stops one or more services that is in a state of 'stop pending'.
.DESCRIPTION
Stop-PendingService is a function that is designed to stop any service
that is hung in the 'stop pending' state. This is accomplished by forcibly
stopping the hung services underlying process.
.EXAMPLE
Stop-PendingService
.NOTES
Author: Mike F Robbins
Website: http://mikefrobbins.com
Twitter: @mikefrobbins
#>
$Services = Get-WmiObject -Class win32_service -Filter "state = 'stop pending'"
if ($Services) {
foreach ($service in $Services) {
try {
Stop-Process -Id $service.processid -Force -PassThru -ErrorAction Stop
}
catch {
Write-Warning -Message "Unexpected Error. Error details: $_.Exception.Message"
}
}
}
else {
Write-Output "There are currently no services with a status of 'Stopping'."
}
}
答案4
如果您有 Windows 管理框架 3.0(powershell 3)或更高版本,这里有一个 Powershell 单行命令。
Stop-Service -Name "https-myWebserver" -Force
还有 Start-Service 和 Restart-Service 命令,但是 Start-Service 命令没有 -force 开关,因为它不需要。