PeterAtkin Posted March 13, 2010 Share Posted March 13, 2010 (edited) Seems the peice of code below does not work as I had expected, the $var only returns "$objItem.MACAddress(0)" and not the mac address as expected, any ideas.$var = GetLANobject("$objItem.MACAddress(0)") MsgBox(1, "Mac", $var) Func GetLANobject($wmiobject) Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($wmiobject) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $wmiobject If @IPAddress2 = $objItem.IPAddress(0) Then Return $wmiobject If @IPAddress3 = $objItem.IPAddress(0) Then Return $wmiobject If @IPAddress4 = $objItem.IPAddress(0) Then Return $wmiobject EndIf ;MsgBox(1, $objItem.IPAddress(0), $wmiobject) Next Else Return "1" ; if you dont have IPSubnet EndIf EndFunc ;==>GetLANobjectFully working code of what I am trying to achive above.Local $gateway = GetLanGW() Func GetLANMACAddress() Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen($objItem.MACAddress(0)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) If @IPAddress2 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) If @IPAddress3 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) If @IPAddress4 = $objItem.IPAddress(0) Then Return $objItem.MACAddress(0) EndIf Next Else Return "N/A" ; if you dont have IPSubnet EndIf EndFunc ;==>GetLANMACAddress Edited March 13, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Pain Posted March 13, 2010 Share Posted March 13, 2010 (edited) Like this? MsgBox(0, "", GetLANMACAddress("$objItem.MACAddress(0)")) Func GetLANMACAddress($obj) Local $colItems = "" Local $strComputer = "localhost" Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If (StringLen($objItem.IPAddress(0)) > 3) And (StringLen(Execute($obj)) > 3) Then If @IPAddress1 = $objItem.IPAddress(0) Then Return Execute($obj) If @IPAddress2 = $objItem.IPAddress(0) Then Return Execute($obj) If @IPAddress3 = $objItem.IPAddress(0) Then Return Execute($obj) If @IPAddress4 = $objItem.IPAddress(0) Then Return Execute($obj) EndIf Next Else Return "N/A" ; if you dont have IPSubnet EndIf EndFunc ;==>GetLANMACAddress Perhaps you'll like to change the name, I used the name of the working example when I modified it. Edited March 13, 2010 by Pain Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 13, 2010 Author Share Posted March 13, 2010 (edited) Wow that was fast, worked a real treat, now another interresting one I tried to use the execute on an array did not work out as expected when I read up on the help file it did not seem to have an array limitation, as you can tell i am lacking some basic fundamental knowledge on how to handle variables so forgive my ignorance, that been said your example has been most enlightening and I was able to convert 5 quite large routine into on small one, so once again thanks.Now the issue below, I want to join the array variable $obj with "[$i][1]" so it will become in this example "$network_printers[$i][1]" for instance, I looked for verious ways to join these toegther but so far to no avail, the important thing is that the end variable "$network_printers[$i][1]" is reconised as an array, is this possible?read_array($vars_file, "Printers", $network_printers) Func read_array($ini_file, $ini_section, $obj) If FileExists($ini_file) Then $var = IniReadSection($ini_file, $ini_section) If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] $var1 = $obj "[$i][1]"; = $var[$i][1] $var2 = $obj "[$i][0]"; = $var[$i][0] MsgBox(4096, "var", $var1 & @CRLF & $var2) ;MsgBox(4096, "Number of Printers :" & $var[0][0], "Key: " & $network_printers[$i][0] & @CRLF & "Value: " & $network_printers[$i][1]) Exit Next $dvar = $var[0][0] Return $dvar EndIf Else $error_code = 1 _put_event(1, "The INI file " & $ini_file & " may not exist or the section " & $ini_section & " within may not exist", @error) EndIf EndFunc ;==>read_arrayOriginal working codeFunc _add_network_printers() For $j = 1 To read_array("vars.ini","Printers") MsgBox(4096, "Number of Printers :" & $number_of_network_printers, "Key: " & $network_printers[$j][0] & @CRLF & "Value: " & $network_printers[$j][1]) $printer= $network_printers[$j][1] _PrinterAdd($printer, 0) Next EndFunc ;==>_add_network_printers Func read_file_into_array($ini_file, $ini_section) If FileExists($ini_file) Then $var = IniReadSection($ini_file, $ini_section) If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] $network_printers[$i][1] = $var[$i][1] $network_printers[$i][0] = $var[$i][0] MsgBox(4096, "Number of Printers :" & $var[0][0], "Key: " & $network_printers[$i][0] & @CRLF & "Value: " & $network_printers[$i][1]) Next $number_of_network_printers = $var[0][0] Return $number_of_network_printers EndIf Else $error_code = 1 _put_event(1, "The INI file " & $ini_file & " may not exist or the section " & $ini_section & " within may not exist", @error) EndIf EndFunc ;==>read_host_file_into_array Edited March 13, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
PeterAtkin Posted March 13, 2010 Author Share Posted March 13, 2010 (edited) I put this one as a new post Merge Array and Text to make a complete Array variable / object to avoid confusion.. Edited March 13, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now