2006-11-09 01:06 取得網路卡的 Physical Address -- ipconfig
?API 好文轉寄 平均分數:0 顆星 投票人數:0 人
我要評分: 底下的方式是執行 ipconfig /all 指令讀取所有網路卡的 Physical Address 到暫存檔內,再開啟該檔案並剖析文字讀取 Physical Address,再將 Physical Address 寫入儲存格內。 |
Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" _ (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long Const SYNCHRONIZE = &H100000 Const INFINITE = &HFFFF Const PROCESS_INFORMATION = &H400 Sub Get_ALL_MAC_Address() Dim TaskID As Long, process_handle As Long Dim MyCmd As String, TempFn As String Dim fso As Object, fnum%, i% Dim linestr As Variant Set fso = CreateObject("Scripting.FileSystemObject") '取得TEMP資料夾及暫存檔名稱 TempFn = fso.GetSpecialFolder(2) & "" & fso.GetTempName '合併指令 MyCmd = "cmd.exe /c ipconfig /all | find /I ""Physical Address"" >> " & TempFn '執行指令並取得 Task ID TaskID = Shell(MyCmd, 0) process_handle = OpenProcess(PROCESS_INFORMATION + SYNCHRONIZE, 0, TaskID) WaitForSingleObject process_handle, INFINITE CloseHandle process_handle fnum = FreeFile '開啟暫存檔 Open TempFn For Input As #fnum Do While Not EOF(fnum) '讀取一行字串 Line Input #fnum, linestr '剖析字串 linestr = Split(linestr, ":") '字串數大於1個時,將第2個字串寫入儲存格 If UBound(linestr) > 0 Then i = i + 1 Cells(i, 1) = trim(linestr(1)) End If Loop '關閉檔案 Close #fnum Set fso = Nothing End Sub
|
