* Program....: GETMAC.PRG * Version....: 1.0 * Author.....: ** Richard G Bean ** * Date.......: February 27, 2001 #DEFINE c_nMaxTries 3 PRIVATE oForm1, lcMACAddress, lnLength, lnTries, lCSaveAddress oform1 = CREATEOBJECT("dummyform") lnTries = 0 DO WHILE lnTries < c_nMaxTries lcMACAddress = oForm1.Olecontrol1.MACAddress && returned in form of XX-XX-XX-XX-XX-XX lcMACAddress = strtran(lcMACAddress, "-", "") && Kill the dashes lnLength = LEN(lcMACAddress) DO CASE CASE lnLength = 12 * Good enuff - just one NIC and we got the value EXIT CASE lnLength = 25 * Got two addresses - just use the last one if it's 12 long (first probably a modem) IF AT(";", lcMACAddress) = 13 lcMACAddress = RIGHT(lcMACAddress, 12) EXIT ENDIF OTHERWISE && Could be a Bad Call - try again for c_MaxTries * Got more than 2 or got wrong length IF MOD((lnLength+1), 13) = 0 && Probably good IF RAT(";", lcMACAddress) = 13 && just use the last one if it's 12 long lcMACAddress = RIGHT(lcMACAddress, 12) EXIT ENDIF ENDIF ENDCASE lnTries = lnTries + 1 ENDDO && .T. IF LEN(lcMACAddress) <> 12 lcMACAddress = " " && make it empty - I can't get a good "read" ENDIF && LEN(lcMACAddress) <> 12 RETURN lcMACAddress ************************************* DEFINE CLASS dummyform AS form DoCreate = .T. Caption = "dummyform" Name = "dummyform" ADD OBJECT olecontrol1 AS MYMAC WITH ; Top = 8, ; Left = 8, ; Height = 100, ; Width = 100, ; Name = "Olecontrol1" ENDDEFINE ************************************* DEFINE CLASS MYMAC as OLEControl OleClass = 'MACAddressOCX.MACAddress' ENDDEFINE *!* EOP: GETMAC.PRG