vbScript - Use wmic to Control Process Priority

Updated Reverend Jim 1 Tallied Votes 2K Views Share

Over the last few days I have been converting old video files from avi to mp4. I've been doing this using the command line version of DivX. This is the process behing the DivXPro GUI and it is named DivXEngine.exe. Converting video files takes a big hit on the CPU and I would prefer to set the process to a lower priority to minimize the impace on my usual tasks. Under Windows 7 there was a utility program that could be used to permanently change a task priority. Unfortunately it no longer works in Windows 10 so I did the next best thing. I coded up a simple script that I could run in the background. Every 10 seconds it resets the priority of the divX process to "below normal". Naturally I use a script to process each of my videos in turn, and after each conversion, a new instance of DivXEngine.exe is created. My ten-second loop script then whacks the new instance back to "below normal".

The tool that accomplishes the priority change is wmic.exe which comes with Windows 10. I am just starting to explore what can be done with wmic. If uou have a process that you need to puch to the back, try wmic and the above script.

rproffitt commented: "Maximum warp Scotty!" +15
'Priority values are
'
'   idle:                4 (this displays as "low" in Task Manager)
'   below normal:        6
'   normal:              8
'   above normal:       10
'   high priority:      13
'   real time:          24
'
'You can use % as a wildcard in the process name as in "%divx%"

Const PROCESS  = "DivXEngine.exe"
Const PRIORITY = "below normal" 

Set wso = CreateObject("Wscript.Shell")
cmd = "wmic process where name=""" & PROCESS & """ call setpriority """ & PRIORITY & """"

Do While True
    wso.Run cmd,0,True      'run hidden and wait for completion
    WScript.Sleep 10000     'sleep for 10 seconds
Loop
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.