将磁盘签名设置为否定

时间:2017-11-13 07:07:00

标签: windows wmi wmi-query wmic get-wmiobject

import wmi
wmi_connector = wmi.WMI()
def get_win_drive_mappings_locally(drivemappings):

        for physical_disk in wmi_connector.Win32_DiskDrive():
            for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
                for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
                 print (physical_disk.Signature)

我正在使用wmi来获取磁盘和签名的信息。 当我打印physical_disk的实例时,输出如下:

instance of Win32_DiskDrive
{
        BytesPerSector = 512;
        Capabilities = {3, 4};
        CapabilityDescriptions = {"Random Access", "Supports Writing"};
        Caption = "XXXXX SCSI Disk Device";
        ConfigManagerErrorCode = 0;
        ConfigManagerUserConfig = FALSE;
        CreationClassName = "Win32_DiskDrive";
        Description = "Disk drive";
        DeviceID = "\\\\.\\PHYSICALDRIVE1";
        FirmwareRevision = "0   ";
        Index = 1;
        InterfaceType = "SCSI";
        Manufacturer = "(Standard disk drives)";
        MediaLoaded = TRUE;
        MediaType = "Fixed hard disk media";
        Model = "XXXX  SCSI Disk Device";
        Name = "\\\\.\\PHYSICALDRIVE1";
        Partitions = 1;
        PNPDeviceID = "SCSI\\DISK&XXXXX&PROD_K\\4&5393C0A&0&000100";
        SCSIBus = 0;
        SCSILogicalUnit = 0;
        SCSIPort = 2;
        SCSITargetId = 1;
        SectorsPerTrack = 63;
        SerialNumber = "XXXXX";
        Signature = **3908409726**;
        Size = "107372805120";
        Status = "OK";
        SystemCreationClassName = "Win32_ComputerSystem";
        SystemName = "SQLSERVER";
        TotalCylinders = "13054";
        TotalHeads = 255;
        TotalSectors = "209712510";
        TotalTracks = "3328770";
        TracksPerCylinder = 255;
};

但是当我打印physical_disk.Signature时,输出是: -386557570 ,我无法理解它出错的地方,预期产量是3908409726

1 个答案:

答案 0 :(得分:1)

-386557570确实是3908409726被解释为32位带符号的整数(在2的补码算术中);可能Python WMI连接器将所有32位值解释为signed。

要将其解释为无符号值,请检查它是否为负数,并在这种情况下添加1<<32

def as_uint32(v):
    if v<0:
        return v + (1<<32)
    return v

# ...
print (as_uint32(physical_disk.Signature))