用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息

网上原码,去了DECODE编码的问题。

PyScripter这个PYTHON的IDE工具在WIN下表现不错哟。

感觉比SPYDER,ERIC,SUBLEME TEXT3之类的好用呀。。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wmi
import os
import sys
import platform
import time

def sys_version():
    c = wmi.WMI ()
    #获取操作系统版本
    for sys in c.Win32_OperatingSystem():
        print "Version:%s" % sys.Caption,"Vernum:%s" % sys.BuildNumber
        print  sys.OSArchitecture#系统是32位还是64位的
        print sys.NumberOfProcesses #当前系统运行的进程总数

def cpu_mem():
    c = wmi.WMI ()
    #CPU类型和内存
    for processor in c.Win32_Processor():
        #print "Processor ID: %s" % processor.DeviceID
        print "Process Name: %s" % processor.Name.strip()
    for Memory in c.Win32_PhysicalMemory():
        print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576)

def cpu_use():
    #5s取一次CPU的使用率
    c = wmi.WMI()
    while True:
        for cpu in c.Win32_Processor():
            timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
            print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
            time.sleep(5)
            break

def disk():
    c = wmi.WMI ()
    #获取硬盘分区
    for physical_disk in c.Win32_DiskDrive ():
        for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
            for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
                print physical_disk.Caption, partition.Caption, logical_disk.Caption

    #获取硬盘使用百分情况
    for disk in c.Win32_LogicalDisk (DriveType=3):
        print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))

def network():
    c = wmi.WMI ()
    #获取MAC和IP地址
    for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1):
        print "MAC: %s" % interface.MACAddress
    for ip_address in interface.IPAddress:
        print "ip_add: %s" % ip_address
    print

    #获取自启动程序的位置
    for s in c.Win32_StartupCommand ():
        print "[%s] %s <%s>" % (s.Location, s.Caption, s.Command)

    #获取当前运行的进程
    for process in c.Win32_Process ():
        print process.ProcessId, process.Name

def main():
    sys_version()
    cpu_mem()
    disk()
    network()
    #cpu_use()

if __name__ == '__main__':
    main()
    print platform.system()
    print platform.release()
    print platform.version()
    print platform.platform()
    print platform.machine()

时间: 2024-08-27 03:10:01

用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息的相关文章

python使用WMI检测windows系统信息、硬盘信息、网卡信息的方法

  本文实例讲述了python使用WMI检测windows系统信息.硬盘信息.网卡信息的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

C/C++获取Windows系统CPU和内存及硬盘使用情况

//1.获取Windows系统内存使用率   [cpp] view plain copy   //windows 内存 使用率   DWORD getWin_MemUsage(){       MEMORYSTATUS ms;       ::GlobalMemoryStatus(&ms);       return ms.dwMemoryLoad;   }       //2.获取windowsCPU使用率   [cpp] view plain copy   __int64 CompareFi

这段百度问答,对我相关有对啊!!!----如何获取Windows系统登陆用户名

如何获取Windows系统登陆用户名   http://zhidao.baidu.com/link?url=Hva9PkVwYZv8KSEWftSqTWe8fqM1dhoq59BurnfADmcOvFjFgJUONb2kQ4KrJUF5KjOTXjCf5SQKYNLhcU_dBMzGGBxFxJCRfxCmamIjUji   ======================= 一般用 GetUserName(或 GetUserNameEx )函数可得到当前登陆登陆用户名(但不总会得到,下面会分析),

PowerShell小技巧之获取Windows系统密码Hash_PowerShell

当你拿到了系统控制权之后如何才能更长的时间内控制已经拿到这台机器呢?作为白帽子,已经在对手防线上撕开一个口子,如果你需要进一步扩大战果,你首先需要做的就是潜伏下来,收集更多的信息便于你判断,便于有更大的收获.用什么方法才能有尽可能高的权限,同时能更有效的隐藏自己,是留webshell,留后门,种木马还是Rootkit?webshell,哪怕是一句话木马都很容易被管理员清除,放了木马,也容易被有经验的管理员查出,不管是早期自己创建进程,进程被干掉就完了,还是注入进程的木马,或者是以服务自启动的木马

用WMI实现Windows系统自动管理

  与以前的操作系统相比,Windows 2K/XP的优点之一是具有更好的可管理性.例如它支持Windows 2000服务器终端服务下的远程管理模式,支持Microsoft管理控制台(MMC),再有一个就是支持WMI.WMI是Windows Management Instrumentation的缩写,即Windows管理规范.WMI有许多用途,其中之一就是通过脚本编程实现管理自动化. 一.为什么要用脚本? 回顾九十年代,Windows NT之所以获得成功,原因之一就在于相对而言这个操作系统比较容

如何获取Windows系统登陆用户名

一般用 GetUserName(或 GetUserNameEx )函数可得到当前登陆登陆用户名(但不总会得到,下面会分析),此系统函数在Win95.WinNT 及以后所有操作系统中都可用.代码如下: BOOL CSecurityTool::GetCurrProcessUser(CString& strName) { BOOL bRet(TRUE); strName = _T(""); DWORD dwSize = MAX_PATH; TCHAR *pszName = new T

PowerShell中获取Windows系统序列号的脚本分享_PowerShell

windows序列号可以直接在注册表中读取,PowerShell要做的只是读出数据后稍作处理,让它更像一个序列号. 复制代码 代码如下: function Get-ProductKey {        $map="BCDFGHJKMPQRTVWXY2346789"     $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").digitalproductid

python使用wmi模块获取windows下硬盘信息的方法

本文实例讲述了python使用wmi模块获取windows下硬盘信息的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45# -*- coding: utf-8 -*- #import ################################

UWP 应用获取各类系统、用户信息 (1) - 设备和系统的基本信息、应用包信息、用户数据账户信息和用户账户信息

原文:UWP 应用获取各类系统.用户信息 (1) - 设备和系统的基本信息.应用包信息.用户数据账户信息和用户账户信息 应用开发中,开发者时常需要获取一些系统.用户信息用于数据统计遥测.问题反馈.用户识别等功能.本文旨在介绍在 Windows UWP 应用中获取一些常用系统.用户信息的方法.示例项目代码可参见 Github: https://github.com/validvoid/UWP-SystemInfoCollector 由于涉及内容较多,故本文会分为多篇展开.本篇介绍获取设备和系统的基