2

I have a windows service that needs to run with High Priority.
At the end of the day I want to use this script to modify the priority after service startup:

Const HIGH = 256

strComputer = "."
strProcess = "BntCapi2.exe"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = '" & strProcess & "'")

For Each objProcess in colProcesses
    objProcess.SetPriority(HIGH)
Next

But currently I am not able to change the priority, even with the taskmanger. The taskmananger throws an "Access Denied" error, but I am logged on as administrator and I changed the user account of the service to administrator, too.

I still get the "access denied" message when trying to change the priority. Any ideas what permission I need to do that?

Jürgen Steinblock
  • 316
  • 1
  • 4
  • 16

3 Answers3

5

I found a way to do this in this blog: http://akshayjain.org/blog/2008/08/hack-unable-to-change-priority-in-task-manager/

If I run this command

ntsd -c qd taskmgr.exe

the taskmanager starts with system privileges and I am able to change the process priority. That means that my wsh script can do this, too. I created a batch file

@ECHO OFF
ntsd -c qd cscript.exe set_service_priority.vbs

and now the process priority get's modified, like I wanted.

Initially I couldn't change process priority because the service ran under the system account. The strange thing is that, even after changing the service user to administrator (that's me ;) I got the "access denied" message. But with this trick that works like a charm.

Jürgen Steinblock
  • 316
  • 1
  • 4
  • 16
1

You might need to add the following to the top of your script:

Set objLoc = createobject("wbemscripting.swbemlocator")
objLoc.Security_.privileges.addasstring "sedebugprivilege", true 

Although.. I wouldn't want to use anything above 128.. (256 = Realtime)

Full list here: http://msdn.microsoft.com/en-us/library/aa393587.aspx

Grizly
  • 2,053
  • 15
  • 20
  • thanks for the update about the right value for high priority. I took my example from this link: http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/16/how-can-i-lower-the-priority-of-a-process-using-a-script.aspx where it is mixed up. – Jürgen Steinblock Sep 08 '10 at 12:54
  • The hint with `sedebugprivilege` looked promissing but unfortunately it didn't help anything. Is there a permission for "change service priority" that the administrator does not have? – Jürgen Steinblock Sep 08 '10 at 12:59
  • Ahh, maybe it should be: `SeIncreaseBasePriorityPrivilege` Whole list here: http://msdn.microsoft.com/en-us/library/aa392758%28v=VS.85%29.aspx – Grizly Sep 08 '10 at 13:14
  • Didn't work either :( The best thing for me is to focus on granting the right to the administrator (since I can't set the permission in task manager) first, any idea how to achive that? – Jürgen Steinblock Sep 09 '10 at 14:33
1

http://setiathome.berkeley.edu/forum_thread.php?id=69381

wmic process where name="notepad.exe" CALL setpriority 32768

Idle: 64 Below Normal: 16384 Normal: 32 Above Normal: 32768 High Priority: 128 Real Time: 256

asdf
  • 11
  • 1
  • 1
    This will probably do the same like the script above, but in this case my problem was that I got a "Access denied" error for a specific service, even from taskmanager. Using ntsd solved this. – Jürgen Steinblock Oct 17 '12 at 06:22