Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

SetPriority with WMI?

Hello All!

I have a litte code but i don't know how can i use it to set the priority of an application.


Const BELOW_NORMAL = 16384;
var
 Locator: ISWbemLocator;
 objWMIService, colProcesses,objProcess: OleVariant;
begin
 Locator:=CreateOleObject('WbemScripting.SWbemLocator') as ISWbemLocator;
 objWMIService:=Locator.ConnectServer('.', 'root\cimv2', '', '', '', '', 0, nil);
 colProcesses:=objWMIService.ExecQuery('Select * from  Win32_Process Where Name = NOTEPAD.EXE');
 objProcess.SetPriority('BELOW_NORMAL');


It returns with the following error message:
'Invalid variant operation'

Who knows the perfect solution?

Thanks in advance!
0
rogerrr
Asked:
rogerrr
  • 2
2 Solutions
 
pcsentinelCommented:
Is the application you want to change the priority for the app you are programming? if so you could just use

SetPriorityClass(GetCurrentProcess,ABOVE_NORMAL_PRIORITY_CLASS);
0
 
ziolkoCommented:
well in this code objProcess in unassigned variant, you have to:
create enumeration on colProcesses find appropriate item and call its method.
SetPriority is method of Win32_Process class

ziolko.
0
 
ziolkoCommented:
heres other way without enumeration (it should spawn calculator:) )

  sr:=FServices.Get('Win32_Process',0,nil);
  inp:=sr.Methods_.Item('Create').InParameters.SpawnInstance_;
  inp.Properties_.item('CommandLine').Value:='C:\WINDOWS\system32\calc.exe';}
  inp.Properties_.item('CurrentDirectory').Value:='C:\WINDOWS\system32\';

  ret:=sr.ExecMethod_('Create',inp);

ziolko.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now