检查 Python 中哪些 RAM 插槽为空

Check which RAM slots are empty in Python

我的电脑有 4 个插槽可以安装 RAM(内存)。我只在第二个插槽中安装了 RAM,其余的都是空的。这是 Windows PC。

是否可以通过 Python 确定哪些插槽安装了 RAM?

Make sure you have win32api installed.

import win32com.client

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_PhysicalMemory")
for objItem in colItems:
    if objItem.BankLabel != None:
        print "BankLabel:" + ` objItem.BankLabel`

代码借用和摘录自:
https://www.activexperts.com/admin/scripts/wmi/python/0344/

延伸阅读:
https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-physicalmemory