Esempio n. 1
0
    def _get_lpt_ports(self):
        ''' Return a dictionary (name -> address) of available LPT ports
        on the system (Windows only). '''

        lpt_ports = {}

        lpt_devices = wmi.GetObject('WinMgmts://').InstancesOf(
            'Win32_ParallelPort')
        for device in lpt_devices:
            id = device.PnpDeviceID
            key = reg.OpenKey(
                reg.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Enum\\' +
                id + '\\Device Parameters')
            portname = reg.QueryValueEx(key, 'PortName')[0]

            # Address can be stored in two places...
            try:
                # For expansion cards
                key = reg.OpenKey(
                    reg.HKEY_LOCAL_MACHINE,
                    'SYSTEM\\CurrentControlSet\\Enum\\' + id + '\\Control')
                conf = reg.QueryValueEx(key, 'AllocConfig')[0]

                # Decode data as signed integers (4 bytes each)
                conf_dec = struct.unpack('%di' % (len(conf) / 4), conf)

                # Find the portaddress at the correct offset
                portaddress = conf_dec[6]

            except WindowsError:
                # For regular ports
                key = reg.OpenKey(
                    reg.HKEY_LOCAL_MACHINE,
                    'SYSTEM\\CurrentControlSet\\Enum\\' + id + '\\LogConf')
                conf = reg.QueryValueEx(key, 'BasicConfigVector')[0]

                # Decode data as signed integers (4 bytes each)
                conf_dec = struct.unpack('%di' % (len(conf) / 4), conf)

                # Find the portaddress at the correct offset
                portaddress = conf_dec[14]

            lpt_ports[portname] = portaddress

        return lpt_ports
Esempio n. 2
0
 def test_class_without_namespace (self):
   wmi_class = wmi.GetObject ("winmgmts:Win32_ComputerSystem")
   self.assert_ (wmi._wmi_class (None, wmi_class)._namespace)
Esempio n. 3
0
__author__ = 'Matt Eland'

import time

import wmi
import win32com.client

c = wmi.WMI()
for s in c.Win32_Service():
    if s.State == 'Stopped':
        print s.Caption, s.State

obj = win32com.client.Dispatch("WbemScripting.SWbemRefresher")
# Create refresher object

WMIService = wmi.GetObject("winmgmts:\\root\cimv2")
#pointer to local WMI service to pass refresher

diskItems = obj.AddEnum(
    WMIService, "Win32_PerfFormattedData_PerfDisk_PhysicalDisk").objectSet
processorItems = obj.AddEnum(
    WMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet
networkItems = obj.AddEnum(
    WMIService, "Win32_PerfFormattedData_Tcpip_NetworkInterface").objectSet
#add services you wish to monitor to refresher, and create pointers to the data
#structures that they modify when you call obj.Refresh()

while 1:
    obj.Refresh()  #Refresh all performance counters
    for item in diskItems:
        print item.Name, " ",
Esempio n. 4
0
__author__ = 'Administrator'
import wmi
connection = wmi.connect_server(server='172.168.10.242',
                                user='******',
                                password='******')
WMI = wmi.GetObject('winmgmts:')
# sql1 = 'SELECT DiskReadsPerSec,DiskWritesPerSec FROM Win32_PerfRawData_PerfDisk_PhysicalDisk WHERE Name="_Total"'
# result =  WMI.ExecQuery(sql1)