簡體   English   中英

遠程啟動服務

[英]Remote start services

我嘗試在用戶輸入后遠程啟動服務。

function Start_Service {
    $ComputerName = $txb_hostname.Text

    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

    $title = 'Start Service'
    $msg   = 'Enter Service Name (e.g. AppVClient):'

    $ServiceName = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

    try {
        (Get-WmiObject Win32_Service -ComputerName $ComputerName -filter "Name='$ServiceName'").StartService()
        LogWrite "$ServiceName started."
    } catch {
        LogWrite "Unable to stop $ServiceName"
    }
}

它只是返回

無法啟動“服務”

幾乎像

(Get-WmiObject Win32_Service -Filter -ComputerName $ComputerName "Name='$ServiceName'").StartService()

不起作用。

任何想法為什么它不起作用?


編輯:

來自catch塊的實際錯誤消息:

缺少參數“過濾器”的參數。 指定類型為'System.String'的參數,然后重試。

(Get-WmiObject Win32_Service -ComputerName $ComputerName -Filter "Name='$ServiceName'").StartService()

移動-Filter可解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM