以管理员身份运行命令,条件为规范[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我想以管理员身份运行这个cmd命令

sleep -m 500

所以我使用了这个命令。

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

谁能告诉我正确的命令呢?我希望它是批量版本。

windows powershell batch-file
1个回答
0
投票

我想到了。

命令是这样的:

powershell -Command "Start-Process -FilePath C:\Windows\System32\sleep.exe -ArgumentList -m,500"
© www.soinside.com 2019 - 2024. All rights reserved.