【问题标题】:Start a program with argument using Powershell to get administrator privilege使用 Powershell 启动带参数的程序以获得管理员权限
【发布时间】:2019-12-24 05:06:02
【问题描述】:

我有一个这样的 .bat 文件。但是我不能通过这个命令以管理员身份运行 SeqEdit.exe。我研究了 Powershell,但我不知道如何正确使用它。请帮我将此命令转换为 powershell 命令格式。 提前谢谢你。

@echo off
cd "C:\Program Files\National Instruments\TestStand 2016\Bin"
start /min "" SeqEdit.exe /runEntryPoint "Test UUTs" "C:\Peritec\111 Renesas for Oita\SLT Test System_ver109c\Sequence\SLT Test_Main_Ver2016.2.seq"

exit 

【问题讨论】:

    标签: powershell batch-file command privileges administrator


    【解决方案1】:

    你可以用这个:

    Set-Location "C:\Program Files\National Instruments\TestStand 2016\Bin" 
    Start-Process -FilePath ".\SeqEdit.exe" -ArgumentList "/runEntryPoint 'Test UUTs' 'C:\Peritec\111 Renesas for Oita\SLT Test System_ver109c\Sequence\SLT Test_Main_Ver2016.2.seq'" -Verb RunAs -WindowStyle minimized
    

    如果你想用 cmd 先创建这个批处理文件:

    @echo off
    echo Set objShell = CreateObject("Shell.Application") > %temp%\sudo.tmp.vbs 
    echo args = Right("%*", (Len("%*") - Len("%1"))) >> %temp%\sudo.tmp.vbs 
    echo objShell.ShellExecute "%1", args, "", "runas" >> %temp%\sudo.tmp.vbs 
    cscript //nologo %temp%\sudo.tmp.vbs
    

    现在从另一个批处理文件运行它:

    pushd "The location of seqedit.exe"
    TheFullPathAndNameOfAboveBatchFile seqedit.exe "arguments" "arguments"
    

    【讨论】:

    • 我想从 CMD 运行。请告诉我等效的命令。谢谢你。它看起来像:powershell -command "....
    • 我已经包含了那个方法。
    • 这比我以前想的要复杂 :( 我会尝试作为您的解决方案。非常感谢您
    • 所以使用第一种方法,如果可行,请接受答案/点赞
    • 我从 PowerShell windows 运行第一个解决方案,我的程序无法理解 ArgumentList 中的命令
    猜你喜欢
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2013-12-13
    • 2018-11-21
    • 1970-01-01
    • 2016-09-29
    • 2011-05-05
    • 2011-06-06
    相关资源
    最近更新 更多