Contact Info

Crumbtrail

ActiveXperts.com » Administration » Scripts » WMI » Python

Win32_NetworkLoginProfile - WMI sample in Python

The foundations for Manageability in Windows 2019/2016/2012/2008 and Windows 10/7/XP are 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.

On this site, you can find many WMI samples.

The Win32_NetworkLoginProfile WMI class can be used in ActiveXperts Network Monitor to monitor your servers.


Win32_NetworkLoginProfile

Description

The Win32_NetworkLoginProfile WMI class represents the network login information of a specific user on a Windows system. This includes, but is not limited to password status, access privileges, disk quotas, and login directory paths.

Example(s)

  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_NetworkLoginProfile")
for objItem in colItems:
    if objItem.AccountExpires != None:
        print "AccountExpires:" + WMIDateStringToDate(objItem.AccountExpires)
    if objItem.AuthorizationFlags != None:
        print "AuthorizationFlags:" + ` objItem.AuthorizationFlags`
    if objItem.BadPasswordCount != None:
        print "BadPasswordCount:" + ` objItem.BadPasswordCount`
    if objItem.Caption != None:
        print "Caption:" + ` objItem.Caption`
    if objItem.CodePage != None:
        print "CodePage:" + ` objItem.CodePage`
    if objItem.Comment != None:
        print "Comment:" + ` objItem.Comment`
    if objItem.CountryCode != None:
        print "CountryCode:" + ` objItem.CountryCode`
    if objItem.Description != None:
        print "Description:" + ` objItem.Description`
    if objItem.Flags != None:
        print "Flags:" + ` objItem.Flags`
    if objItem.FullName != None:
        print "FullName:" + ` objItem.FullName`
    if objItem.HomeDirectory != None:
        print "HomeDirectory:" + ` objItem.HomeDirectory`
    if objItem.HomeDirectoryDrive != None:
        print "HomeDirectoryDrive:" + ` objItem.HomeDirectoryDrive`
    if objItem.LastLogoff != None:
        print "LastLogoff:" + WMIDateStringToDate(objItem.LastLogoff)
    if objItem.LastLogon != None:
        print "LastLogon:" + WMIDateStringToDate(objItem.LastLogon)
    if objItem.LogonHours != None:
        print "LogonHours:" + ` objItem.LogonHours`
    if objItem.LogonServer != None:
        print "LogonServer:" + ` objItem.LogonServer`
    if objItem.MaximumStorage != None:
        print "MaximumStorage:" + ` objItem.MaximumStorage`
    if objItem.Name != None:
        print "Name:" + ` objItem.Name`
    if objItem.NumberOfLogons != None:
        print "NumberOfLogons:" + ` objItem.NumberOfLogons`
    if objItem.Parameters != None:
        print "Parameters:" + ` objItem.Parameters`
    if objItem.PasswordAge != None:
        print "PasswordAge:" + WMIDateStringToDate(objItem.PasswordAge)
    if objItem.PasswordExpires != None:
        print "PasswordExpires:" + WMIDateStringToDate(objItem.PasswordExpires)
    if objItem.PrimaryGroupId != None:
        print "PrimaryGroupId:" + ` objItem.PrimaryGroupId`
    if objItem.Privileges != None:
        print "Privileges:" + ` objItem.Privileges`
    if objItem.Profile != None:
        print "Profile:" + ` objItem.Profile`
    if objItem.ScriptPath != None:
        print "ScriptPath:" + ` objItem.ScriptPath`
    if objItem.SettingID != None:
        print "SettingID:" + ` objItem.SettingID`
    if objItem.UnitsPerWeek != None:
        print "UnitsPerWeek:" + ` objItem.UnitsPerWeek`
    if objItem.UserComment != None:
        print "UserComment:" + ` objItem.UserComment`
    if objItem.UserId != None:
        print "UserId:" + ` objItem.UserId`
    if objItem.UserType != None:
        print "UserType:" + ` objItem.UserType`
    if objItem.Workstations != None:
        print "Workstations:" + ` objItem.Workstations`