取得網路卡的 Physical Address -- ipconfig:Excel 遊樂場:Xuite日誌
  • 文章分類
  • 搜尋文章
  • 關鍵字
  • 最新回應
  • Re:用驗證選圖片,by(jade)於2008-07-18
    Re:用驗證選圖片,by(迷羊)於2008-07-10
    Re:多重資料驗證,by(沙拉油)於2008-07-09
    Re:多重資料驗證,by(背景音樂mavis)於2008-07-08
    Re:Excel 說明內找不到的函數,by(基哥)於2008-06-30
    Re:Excel 說明內找不到的函數,by(沙拉油)於2008-06-26
    Re:Excel 說明內找不到的函數,by(基哥)於2008-06-26
    Re:利用WEB查詢換算匯率,by(Daniel)於2008-06-13
    Re:用驗證選圖片,by(Suzen)於2008-06-04
    Re:利用WEB查詢換算匯率,by(沙拉油)於2008-03-20
  • 參觀人氣統計
  • 日曆
  • 我的發燒文
  • 累積 | 今日
    loading......
  • 沙拉油
  • 最愛連結
  • MP3_Player
  • 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



    沙拉油 / Xuite日誌 / 回應(2) / 引用(0) / 好文轉寄
  • 回應