我希望在启动时启动vbs脚本,该脚本将以管理员身份启动另一个程序,并将该程序的优先级设置为高于正常或高优先级。
我目前已使其能够以管理员身份启动程序,但一直无法设置进程级别。
Set app = CreateObject("Shell.Application")
app.ShellExecute """d:\SYNC\Dropbox\PORTABLE_PROGRAMS\ahk\Navigare\KeyboardEnchancer\KeyboardEnchancer.exe""", , , "runas", 3
答案 0 :(得分:1)
我编辑了答案以解决您的权限问题,该脚本现在可以自动提升为以管理员身份运行,有关更多信息,请访问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和ShellExecute method。