vbs 运行 程序作为管理员并具有优先级

vbs run program as admin and with a priority level

我想在启动时启动一个 vbs 脚本,该脚本将以管理员身份启动另一个程序并将该程序的优先级设置为高于正常或高优先级。

我目前已经成功以管理员身份启动该程序,但仍坚持设置进程级别。

Set app = CreateObject("Shell.Application")
app.ShellExecute """d:\SYNC\Dropbox\PORTABLE_PROGRAMS\ahk\Navigare\KeyboardEnchancer\KeyboardEnchancer.exe""", , , "runas", 3

我编辑了答案以解决您的权限问题,脚本现在以管理员身份自动提升为 运行,更多信息请访问:How to Automatically Elevate a Vbscript to Run it as Administrator?。在我的机器上测试并完美运行。

If WScript.Arguments.length = 0 Then

  Set objShell = CreateObject("Shell.Application")
   'Pass a bogus argument, say [ uac]
  objShell.ShellExecute "wscript.exe", Chr(34) & _
    WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1

Else

    Set objShell= CreateObject("Shell.Application")

    strComputer = "."
    Const HIGH_PRIORITY = 128
    processName = "notepad.exe"   ' The process name of your app
    appName = "C:\Windows\System32\notepad.exe" ' The app you want to run

    objShell.ShellExecute appName, , , "runas", 1

    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

    Set colProcesses = objWMIService.ExecQuery _
        ("Select * from Win32_Process Where Name = '" & processName & "'")

    For Each p in colProcesses  
        p.SetPriority(HIGH_PRIORITY)
    Next

End If

更多信息:SetPriority method of the Win32_Process class and ShellExecute method.