简体   繁体   English

_wmi_object的copy.deepcopy()导致异常

[英]copy.deepcopy() of a _wmi_object results in Exception

I am using WMI 1.4.9 in Python, to access WMI. 我在Python中使用WMI 1.4.9来访问WMI。

I would like to do a deepcopy of a _wmi_object that is returned as part of WQL that I perform using the wmi module in python. 我想对_wmi_object做一个深层复制,它是我在python中使用wmi模块执行的WQL的一部分返回的。

My code is as shown below, 我的代码如下所示,

aproc = wmi.WMI(moniker=self._wmi_namespace).query("SELECT * FROM Win32_Process WHERE Name = 'svchost.exe'")[0]
copiedproc = copy.deepcopy(aproc)

But i get this exception, when deepcopy(..) is performed. 但是,当执行deepcopy(..)时,出现此异常。

object.__new__(PyIDispatch) is not safe, use PyIDispatch.__new__()

I do not want to maintain the reference, instead I want the object to be deep copied, before I store them and make use of them. 我不想维护引用,而是希望在存储和使用对象之前将对象进行深复制。

Is it possible? 可能吗?

PyIDispatch cannot be copied. PyIDispatch无法复制。 Objects that are derivative of IDispatch can be only created new. 只能创建新的IDispatch派生对象。

If using python WMI module, you could only create a new WMI object and copy the properties of older object one by one into the newer one. 如果使用python WMI模块,则只能创建一个新的WMI对象,并将旧对象的属性一一复制到新对象中。

For exaemple, creating a new Win32_Process instance, 例如,创建一个新的Win32_Process实例,

newproc = wmi.WMI().Win32_Process.new()

Then update each property of this instance with older instance's property. 然后,使用较旧实例的属性更新该实例的每个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM