vbs以管理员身份运行程序并具有优先级


نسر الصحراء
2025-02-07 08:18:03 (1月前)


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

我目前已经开始发布……

2 条回复
  1. 0# 1号 | 2019-08-31 10-32



    我编辑了解决您的权限问题的答案,该脚本现在自我提升以管理员身份运行,更多信息位于:

    如何自动提升Vbscript以管理员身份运行它?

    。在我的机器上完美地测试和工作。




    1. If WScript.Arguments.length = 0 Then

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

    3. Else

    4. Set objShell= CreateObject("Shell.Application")
    5. strComputer = "."
    6. Const HIGH_PRIORITY = 128
    7. processName = "notepad.exe"   ' The process name of your app
    8. appName = "C:\Windows\System32\notepad.exe" ' The app you want to run
    9. objShell.ShellExecute appName, , , "runas", 1
    10. Set objWMIService = GetObject("winmgmts:" _
    11.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    12. Set colProcesses = objWMIService.ExecQuery _
    13.     ("Select * from Win32_Process Where Name = '" & processName & "'")
    14. For Each p in colProcesses  
    15.     p.SetPriority(HIGH_PRIORITY)
    16. Next
    17. End If

    18. </code>


    更多信息:

    Win32_Process类的SetPriority方法



    ShellExecute方法



登录 后才能参与评论