2017-12-18 251 views
0

條件,我想以管理員身份運行命令以管理員身份與規格

sleep -m 500 

所以我用這個命令來運行這個命令cmd

powershell -Command "Start-Process sleep.exe -m 500 -Verb runas" 

錯誤出現了:

 
Start-Process : A parameter cannot be found that matches parameter name 'm'. 
At line:1 char:47 
+ Start-Process C:\Windows\System32\sleep.exe -m <<<< 500 -Verb runas 
    + CategoryInfo   : InvalidArgument: (:) [Start-Process], ParameterBindingException 
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand 

然後,我用這個命令

powershell -Command "Start-Process 'sleep.exe -m 500' -Verb runas" 

錯誤出現了:

 
Start-Process : This command cannot be executed due to the error: The system cannot find 
the file specified. 
At line:1 char:14 
+ Start-Process <<<< 'C:\Windows\System32\sleep.exe -m 500' -Verb runas 
    + CategoryInfo   : InvalidOperation: (:) [Start-Process], InvalidOperationException 
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand 

然後,我用這樣的:

powershell -Command "Start-Process sleep.exe /m 500 -Verb runas" 

錯誤出現了:

 
Start-Process : A positional parameter cannot be found that accepts argument '500'. 
At line:1 char:14 
+ Start-Process <<<< C:\Windows\System32\sleep.exe /m 500 -Verb runas 
    + CategoryInfo   : InvalidArgument: (:) [Start-Process], ParameterBindingException 
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand 

誰能告訴我正確的命令呢?我希望它是批處理版本。

+0

'PowerShell幫助啓動process' – ACatInLove

+1

PowerShell和批次是完全不同的語言 – SomethingDark

+0

是的,我知道,我只是無法弄清楚如何運行'睡眠 - m 500'作爲管理員使用powershell ..是啊,我知道如何使用'-verb runas'作爲管理員運行它,但我怎樣才能執行我想運行的命令('sleep -m 500')? – scriptmastere02

回答

0

我想通了。

的命令是這樣的:

powershell -Command "Start-Process -FilePath C:\Windows\System32\sleep.exe -ArgumentList -m,500" 
+0

謝謝,ACatInLove讓我看到'powershell help start-process':P – scriptmastere02

+0

如果您正在尋找更多的PowerShell原生函數,請使用'Start-Sleep' –

+0

nope我希望它可以用於任何程序:) – scriptmastere02

相關問題