本文整理匯總了Python中wmi.WMI屬性的典型用法代碼示例。如果您正苦於以下問題:Python wmi.WMI屬性的具體用法?Python wmi.WMI怎麽用?Python wmi.WMI使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類wmi
的用法示例。
在下文中一共展示了wmi.WMI屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wmi_get_physicaldrive_info_ex
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def wmi_get_physicaldrive_info_ex(diskIndex):
drv_list = [d for d in wmi.WMI().Win32_DiskDrive()
if d.Index == diskIndex]
assert len(drv_list)==1
d = collect_relevant_physicaldrive_info(drv_list[0])
r = {}
for src, dst in [
('Size', 'size_total'),
('Model', 'model'),
('Manufacturer', 'vendor'),
('MediaType', 'mediatype'),
('SerialNumber', 'uuid'),
('DeviceID', 'label'),
]:
r[dst] = getattr(d, src)
r['devtype'] = 'disk'
r['size_free'] = 0
r['file_system'] = 'N/A'
r['mount_point'] = 'N/A'
return r
示例2: process_exist
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def process_exist(process_name):
"""
Detect if process exist/ running and kill it.
:param process_name: process name to check
:return: True if processis killed else False
"""
if platform.system() == 'Windows':
import signal
import wmi
c = wmi.WMI()
for process in c.Win32_Process():
if process_name in process.Name:
log(process_name + ' exist...')
log(str(process.ProcessId) + ' ' + str(process.Name))
log("Having Windows explorer won't allow dd.exe to write ISO image properly."
"\nKilling the process..")
try:
os.kill(process.ProcessId, signal.SIGTERM)
return True
except:
log('Unable to kill process ' + str(process.ProcessId))
return False
示例3: initialize_hwmon
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def initialize_hwmon():
"""Create a WMI object and verify that OpenHardwareMonitor is installed."""
# Access the OpenHWMon WMI interface
try:
hwmon = wmi.WMI(namespace="root\OpenHardwareMonitor")
return hwmon
# WMI exception (e.g. no namespace "root\OpenHardwareMonitor" indicates OpenHWMon is not installed
except:
helper.show_error("OpenHardwareMonitor WMI data not found.\n\n"
"Please make sure that OpenHardwareMonitor is installed.\n\n"
"Latest version is available at:\n\n"
"http://openhardwaremonitor.org\n\n"
"The application will now exit.")
sys.exit(0)
示例4: _get_keys
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def _get_keys(self):
"""A WMI object is uniquely defined by a set of properties
which constitute its keys. Lazily retrieves the keys for this
instance or class.
:returns: list of key property names
"""
# NB You can get the keys of an instance more directly, via
# Path\_.Keys but this doesn't apply to classes. The technique
# here appears to work for both.
if self._keys is None:
_set(self, "_keys", [])
for property in self.ole_object.Properties_:
for qualifier in property.Qualifiers_:
if qualifier.Name == "key" and qualifier.Value:
self._keys.append(property.Name)
return self._keys
示例5: associators
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def associators(self, wmi_association_class="", wmi_result_class=""):
"""Return a list of objects related to this one, optionally limited
either by association class (ie the name of the class which relates
them) or by result class (ie the name of the class which would be
retrieved)::
c = wmi.WMI ()
pp = c.Win32_ParallelPort ()[0]
for i in pp.associators (wmi_association_class="Win32_PortResource"):
print i
for i in pp.associators (wmi_result_class="Win32_PnPEntity"):
print i
"""
try:
return [
_wmi_object(i) for i in \
self.ole_object.Associators_(
strAssocClass=wmi_association_class,
strResultClass=wmi_result_class
)
]
except pywintypes.com_error:
handle_com_error()
示例6: query
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def query(self, fields=[], **where_clause):
"""Make it slightly easier to query against the class,
by calling the namespace's query with the class preset.
Won't work if the class has been instantiated directly.
"""
#
# FIXME: Not clear if this can ever happen
#
if self._namespace is None:
raise x_wmi_no_namespace("You cannot query directly from a WMI class")
try:
field_list = ", ".join(fields) or "*"
wql = "SELECT " + field_list + " FROM " + self._class_name
if where_clause:
wql += " WHERE " + " AND ".join(["%s = %r" % (k, str(v)) for k, v in where_clause.items()])
return self._namespace.query(wql, self, fields)
except pywintypes.com_error:
handle_com_error()
示例7: watch_for
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def watch_for(
self,
notification_type="operation",
delay_secs=1,
fields=[],
**where_clause
):
if self._namespace is None:
raise x_wmi_no_namespace("You cannot watch directly from a WMI class")
valid_notification_types = ("operation", "creation", "deletion", "modification")
if notification_type.lower() not in valid_notification_types:
raise x_wmi("notification_type must be one of %s" % ", ".join(valid_notification_types))
return self._namespace.watch_for(
notification_type=notification_type,
wmi_class=self,
delay_secs=delay_secs,
fields=fields,
**where_clause
)
示例8: Registry
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def Registry(
computer=None,
impersonation_level="Impersonate",
authentication_level="Default",
authority=None,
privileges=None,
moniker=None
):
warnings.warn("This function can be implemented using wmi.WMI (namespace='DEFAULT').StdRegProv", DeprecationWarning)
if not moniker:
moniker = construct_moniker(
computer=computer,
impersonation_level=impersonation_level,
authentication_level=authentication_level,
authority=authority,
privileges=privileges,
namespace="default",
suffix="StdRegProv"
)
try:
return _wmi_object(GetObject(moniker))
except pywintypes.com_error:
handle_com_error()
示例9: __init__
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def __init__(self, machine_identification_string, **kwargs):
"""Constructor for UserDefaultsStorageProvider"""
super(WMIStorageProvider, self).__init__()
self._machine_id_string = machine_identification_string
self._wmi_client = wmi.WMI()
self._wmi_client_dll = ctypes.cdll.LoadLibrary(
os.path.join(os.path.dirname(__file__), WMI_CLIENT_DLL_PATH))
self._namespace = kwargs["namespace"]
self._class_name = self._generate_bucket_name()
# calculate number of available buckets, used for modulus division
# when calculating the bucket index
self._buckets_names = [self._class_name]
self._buckets_count = len(self._buckets_names)
self._create_bucket()
logger.debug("namespace: %s" % self._namespace)
logger.debug("root class name: %s" % self._class_name)
示例10: _compat_conn
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def _compat_conn(self):
if not self._compat_conn_attr:
if not BaseUtilsVirt._os_version:
# hostutils cannot be used for this, it would end up in
# a circular import.
os_version = wmi.WMI().Win32_OperatingSystem()[0].Version
BaseUtilsVirt._os_version = list(
map(int, os_version.split('.')))
if BaseUtilsVirt._os_version >= [6, 3]:
self._compat_conn_attr = self._conn
else:
self._compat_conn_attr = self._get_wmi_compat_conn(
moniker=self._wmi_namespace % self._host)
return self._compat_conn_attr
示例11: wmi_get_drive_info
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def wmi_get_drive_info(usb_disk):
assert platform.system() == 'Windows'
for partition in wmi.WMI().Win32_DiskPartition():
logical_disks = partition.associators("Win32_LogicalDiskToPartition")
# Here, 'disk' is a windows logical drive rather than a physical drive
for disk in logical_disks:
if disk.Caption == usb_disk:
return (partition, disk)
raise RuntimeError('Failed to obtain drive information ' + usb_disk)
示例12: wmi_get_physicaldrive_info
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def wmi_get_physicaldrive_info(usb_disk):
"Return information about the drive that contains 'usb_disk'."
partition, disk = wmi_get_drive_info(usb_disk)
import wmi
c = wmi.WMI()
drv_list = [d for d in c.Win32_DiskDrive()
if d.Index == partition.DiskIndex]
assert len(drv_list)==1
return collect_relevant_physicaldrive_info(drv_list[0])
示例13: wmi_get_physicaldrive_info_all
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def wmi_get_physicaldrive_info_all():
c = wmi.WMI()
L = [collect_relevant_physicaldrive_info(d) for d in c.Win32_DiskDrive()]
L.sort(key=lambda x: x.Index)
return L
示例14: wmi_get_volume_info_all
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def wmi_get_volume_info_all():
r = {}
for dindex, volumes in [
(p.DiskIndex, map(lambda d: collect_relevant_volume_info(d),
p.associators("Win32_LogicalDiskToPartition")))
for p in wmi.WMI().Win32_DiskPartition()]:
r.setdefault(dindex, []).extend(volumes)
for dindex, volumes in r.items():
volumes.sort(key=lambda x: x.DeviceID)
return r
示例15: get_reader
# 需要導入模塊: import wmi [as 別名]
# 或者: from wmi import WMI [as 別名]
def get_reader(cls):
import wmi
import pythoncom
def temperature_reader():
pythoncom.CoInitialize()
w = wmi.WMI(namespace='root\\wmi')
temperature = w.MSAcpi_ThermalZoneTemperature()[0]
temperature = int(temperature.CurrentTemperature / 10.0 - 273.15)
return temperature
return temperature_reader