停止服务 Cmdlet 无法打开存在的服务 [英] Stop-Service Cmdlet not able to open service that exists

查看:43
本文介绍了停止服务 Cmdlet 无法打开存在的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 PowerShell 脚本来停止本地机器上的服务.

I am trying to write a PowerShell script to stop services on the local machine.

当我运行 get-service cmdlet 时,它按预期工作.当我使用 stop-service cmdlet 时,它错误地指出不存在具有我指定名称的服务.如果这是真的,get-service cmdlet 肯定会抛出同样的错误.

When I run the get-service cmdlet it works as expected. When I use the stop-service cmdlet, It errors stating that no service exists with the name I specify. If this was true surely the get-service cmdlet would throw the same error.

Get-Service "Service 1" # Returns Service and status
Stop-Service "Service 1" # Throws error below:

Stop-Service : Service 'Service 1' cannot be stopped due to the following error: Cannot open Service 1 service on computer '.'.

使用 stop-service cmdlet 有什么技巧吗?

Is there a trick when using the stop-service cmdlet?

推荐答案

解决方案是以管理员身份运行 PowerShell.这样做后,停止服务工作正常.

Solution was to run PowerShell as an administrator. Stop-Service worked ok after doing that.

这篇关于停止服务 Cmdlet 无法打开存在的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆