香港新浪網 MySinaBlog
« 上一篇 | 下一篇 »
Emily | 6th Mar 2007, 12:56 PM | Script | (2633 Reads)

WMI Example: Hard Disk Physical Serial Number

All Windows Platform

 

Private Function HD_SNo(DrvIdx As Byte) As String

' 取得硬碟序號
' 當有多顆硬碟時 ,可調整為 1 , 2 .. 依此類推


Dim strCls As String, strKey As String
Dim WMI As Object

Set WMI = GetObject("winmgmts:")
strCls = "Win32_PhysicalMedia"
strKey = strCls & ".Tag=""\\\\.\\PHYSICALDRIVE" & DrvIdx & """"
HD_SNo = Trim(WMI.InstancesOf(strCls)(strKey).SerialNumber)

End Function

Sub
HDSerial()
MsgBox HD_SNo(0)  '當有多顆硬碟時 ,可調整為 1 , 2 .. 依此類推
End Sub

mySinaBlog 不支援斜線,斜線現用全形\取代 ,請改回。

mySinaBlog does not support Slash , please replace \ by Slash


[4]

you are great

lung
[引用] | 作者 lung | 7th Dec 2007 17:49 PM | [舉報垃圾留言]

[3]

hi emily !

now it is ok! Thanx


[引用] | 作者 icdenetim@gmail.com | 23rd Apr 2007 00:25 AM | [舉報垃圾留言]

[2]

Hi icdenetim,

It tested ok in Office Xp.

mySinaBlog does not support Slash , please replace \ by Slash.

Sub HDSerial()
MsgBox HD_SNo(0)
End Sub

The above zero means the first hardisk installed, you can enter 1, 2, 3 etc.

Regards
Emily


[引用] | 作者 Emily | 21st Apr 2007 17:19 PM | [舉報垃圾留言]

[1]

hi..
it is about code above. i get 'run time error' on line HD_SNo = Trim(WMI.InstancesOf(strCls)(strKey).SerialNumber)

Any solution?
By the way, i hope this mail reaches you. It makes difficult to understand because all words around mail-box chinese.
my mail: icdenetim@gmail.com
regards..


[引用] | 作者 icdenetim@gmail.com | 19th Apr 2007 17:43 PM | [舉報垃圾留言]