Is there a way to deprioritize a vbs script ? I need to put my script on a production machine, but sometimes it will spike and use all the cpu for a moment, and I was told that my script was no go unless I can rail it down. Is there a win version of unix's nice ? Thanks
You can run the script using the start command, eg: start /BELOWNORMAL <command_to_run>
Alternative, you can also use vbs itself to control the priority; however, I'm not sure if you can't control its own priority. I believe you can do it though.
The following code will set priority level to below normal. The trick is to determine which process that you want to change the priority for. If you have multiple scripts running at the same time, this could be a problem. But it should get you started.
==================================================================================== set wmi = GetObject("WinMgmts:{ImpersonationLevel=Impersonate}!//./root/cimv2") Set processes = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name='cscript.exe'") For Each process In processes process.setpriority 16384 Next
quote:set wmi = GetObject("WinMgmts:{ImpersonationLevel=Impersonate}!//./root/cimv2") Set processes = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name='funky1.exe.exe'") For Each process In processes process.setpriority 16384 Next
So if I copy cscript.exe to funky1.exe, run my vbs script funky1 prog.vbs
I would then run this separately to deprioritize ?
You could say that. When you run that script, it will look for a process with name equals to cscript.exe. If it is found, it will lower its process priority. Also, I noticed a typo above "funky1.exe.exe".
That sounds like a good idea to distinguish between different scripts running simultaneously though.
There are differences between use wscript.sleep to pause the entire script (nearly no CPU usage) and lower the process priority of the script. Wscript.sleep will cause the script to stop executing completely. If you stop the script at "busy" places, it is not "busy" anymore. However, when the script resumes running again, it would become busy again.
The idea of modifying the process priority is to control the amount of CPU time allocating to a specific process. By default, all process (except a few system process which has much higher priority) receives an equal amount of CPU time (CPU execution cycles) and thus shared the CPU power equally. When one process consumes more CPU cycles than others, such as when you use CPU intensitive applications or play games, others will lose their share of CPU cycles and appear slow in response time or even to an halt. While I'm not certain what causeed his script to use large amount of CPU cycles, lowering the priority of the script would make other processes running more smoothly.