How to set process priority using pywin32 and WMI?

自作多情 提交于 2019-12-01 23:21:23

I encountered the same problem as I was playing with 'GetOwner'.

Just tried this, inspired from WMI:

# using proc as in your code

# this line seems to provide the dispatch interface on the COM object
disp = Dispatch(proc)

# this one gets the method definition
method = disp.Methods_('SetPriority')

# the input parameters, and their description
in_parameters = method.InParameters
in_parameter_names = [(i.Name, i.IsArray) for i in in_parameters.Properties_] \
  if not in_parameters is None else [] # not needed here
# >> print in_parameter_names
# [(u'Priority', False)]

# the priority parameter, and setting its value
in_parameters.Properties_['Priority'].Value = 0x40

# doing the call
return_values = disp.ExecMethod_ (method.Name, in_parameters)

For your sample, the following could be skipped. To parse the return values, just do the same as the inputs:

out_parameters = method.OutParameters
out_parameter_names = [(i.Name, i.IsArray) for i in out_parameters.Properties_] \
  if not out_parameters is None else []
res = [return_values.Properties_(i[0]).Value for i in out_parameter_names]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!