用于重新启动服务的 PowerShell 脚本

标签 powershell windows-services keyboard-shortcuts shortcut

我的任务是按键盘序列,例如 Ctrl +Shift +R,重新启动 Windows 服务。

我有一个在 PowerShell ISE 中运行良好的脚本,当以管理权限启动时。

当我尝试使用 PowerShell 脚本时,由于管理权限不足而失败。我可以让它与老式的 bat 文件一起工作,但不能与 PowerShell 一起工作,这真是令人恼火。

问题的根源在于 PowerShell 脚本的快捷方式的管理权限框变灰。到目前为止,还没有解决方法可以克服这个特权问题。

有任何想法吗?

最佳答案

一种方法是在脚本中启动另一个提升的 PowerShell session ,如下所示:

Start-Process PowerShell.exe -arg '-nologo -noprofile script.ps1' -verb runas

这应该会提示提升新的 PowerShell session 。我认为您应该能够设置 -WindowStyle 参数以使新窗口不会出现(如果您需要该行为)。请注意,您需要指定现有脚本的完整路径。

关于用于重新启动服务的 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2835480/

相关文章:

windows-services - Wix 安装程序替换 INSTSRV 和 SRVANY 以进行用户定义的服务安装

eclipse - 撤消快捷方式在 Eclipse 中不起作用

wpf - 我可以为 WPF 中的一系列键创建 KeyBinding 吗?

powershell - 如何将函数放入我希望能够直接调用的 Powershell 脚本文件中?

powershell - 从 PowerShell 清除 Azure Web 应用程序配置设置

powershell - 遍历结果集

javascript - 用于模拟按键的 Jquery 脚本按下不运行键盘快捷键

powershell - 将对象转换为字符串数组 Powershell

c++ - Windows服务创建文件的默认目录在哪里?

c# - 通过 `Configuration.Install.Installer` 安装长期运行的服务时如何将参数传递给 `installutil`