Contact Info

Crumbtrail

ActiveXperts.com » Administration » Scripts » WMI » python sample

Win32_ShadowCopy python sample code

The foundations for Manageability in Windows is Windows Management Instrumentation (WMI; formerly WBEM) and WMI extensions for Windows Driver Model (WDM).

ActiveXperts Network Monitor provides the ability to build monitor check routines based on WMI. ActiveXperts has collected more than a hundred WMI samples. You can use these samples as a base for new check routines you can write yourself. The Win32_ShadowCopy WMI class can be used in ActiveXperts Network Monitor to monitor your servers.


Sample Code

import win32com.client
def WMIDateStringToDate(dtmDate):
    strDateTime = ""
    if (dtmDate[4] == 0):
        strDateTime = dtmDate[5] + '/'
    else:
        strDateTime = dtmDate[4] + dtmDate[5] + '/'
    if (dtmDate[6] == 0):
        strDateTime = strDateTime + dtmDate[7] + '/'
    else:
        strDateTime = strDateTime + dtmDate[6] + dtmDate[7] + '/'
        strDateTime = strDateTime + dtmDate[0] + dtmDate[1] + dtmDate[2] + dtmDate[3] + " " + dtmDate[8] + dtmDate[9] + ":" + dtmDate[10] + dtmDate[11] +':' + dtmDate[12] + dtmDate[13]
    return strDateTime

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_ShadowCopy")
for objItem in colItems:
    if objItem.Caption != None:
        print "Caption:" + ` objItem.Caption`
    if objItem.ClientAccessible != None:
        print "ClientAccessible:" + ` objItem.ClientAccessible`
    if objItem.Count != None:
        print "Count:" + ` objItem.Count`
    if objItem.Description != None:
        print "Description:" + ` objItem.Description`
    if objItem.DeviceObject != None:
        print "DeviceObject:" + ` objItem.DeviceObject`
    if objItem.Differential != None:
        print "Differential:" + ` objItem.Differential`
    if objItem.ExposedLocally != None:
        print "ExposedLocally:" + ` objItem.ExposedLocally`
    if objItem.ExposedName != None:
        print "ExposedName:" + ` objItem.ExposedName`
    if objItem.ExposedPath != None:
        print "ExposedPath:" + ` objItem.ExposedPath`
    if objItem.ExposedRemotely != None:
        print "ExposedRemotely:" + ` objItem.ExposedRemotely`
    if objItem.HardwareAssisted != None:
        print "HardwareAssisted:" + ` objItem.HardwareAssisted`
    if objItem.ID != None:
        print "ID:" + ` objItem.ID`
    if objItem.Imported != None:
        print "Imported:" + ` objItem.Imported`
    if objItem.InstallDate != None:
        print "InstallDate:" + WMIDateStringToDate(objItem.InstallDate)
    if objItem.Name != None:
        print "Name:" + ` objItem.Name`
    if objItem.NoAutoRelease != None:
        print "NoAutoRelease:" + ` objItem.NoAutoRelease`
    if objItem.NotSurfaced != None:
        print "NotSurfaced:" + ` objItem.NotSurfaced`
    if objItem.NoWriters != None:
        print "NoWriters:" + ` objItem.NoWriters`
    if objItem.OriginatingMachine != None:
        print "OriginatingMachine:" + ` objItem.OriginatingMachine`
    if objItem.Persistent != None:
        print "Persistent:" + ` objItem.Persistent`
    if objItem.Plex != None:
        print "Plex:" + ` objItem.Plex`
    if objItem.ProviderID != None:
        print "ProviderID:" + ` objItem.ProviderID`
    if objItem.ServiceMachine != None:
        print "ServiceMachine:" + ` objItem.ServiceMachine`
    if objItem.SetID != None:
        print "SetID:" + ` objItem.SetID`
    if objItem.State != None:
        print "State:" + ` objItem.State`
    if objItem.Status != None:
        print "Status:" + ` objItem.Status`
    if objItem.Transportable != None:
        print "Transportable:" + ` objItem.Transportable`
    if objItem.VolumeName != None:
        print "VolumeName:" + ` objItem.VolumeName`