1

在 VB6 中,我得到这样的卷的序列号:

Temp1 = String$(255, Chr$(0))
Temp2 = String$(255, Chr$(0))
r = GetVolumeInformation(uDrive, Temp1, StrLen(Temp1), lSerialNumber, 0, 0, Temp2, StrLen(Temp2))

GetPartitionSerialNumber = lSerialNumber

在 VB.NET 我使用

    Dim disk As System.Management.ManagementObject = New System.Management.ManagementObject("win32_logicaldisk.deviceid=""" + uDrive + ":""")
    disk.Get()
    Dim SerialNumber As String = disk("VolumeSerialNumber").ToString()

VB6 返回 -1870518177,但 VB.NET 返回 9082285F。

有人可以告诉我我需要做什么才能在 .NET 中获得结果 -1870518177 吗?

谢谢!

4

2 回答 2

2

While Val("&H" & ...) will work, it's the old VB6 way of doing things which isn't optimal. The better way to do it would be:

Dim iSerial As Integer = Convert.ToInt32(sSerialNumber, 16) 

The 16 parameter specifies the base (hexidecimal is base 16).

于 2012-12-17T11:00:10.130 回答
0

Dim iSerial As Integer = Val("&H" & sSerialNumber)

于 2012-12-17T10:03:21.253 回答