zoel Posted Thursday at 09:42 PM Posted Thursday at 09:42 PM Hi community, I am making a script and I want it to show on a GUI the MAC address of my computer, the script runs without errors, but it does not show my MAC address. Here is the code: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Process.au3> ; Include for process handling ; Get the MAC address Local $sMAC = _GetMACAddress() ; Create the GUI GUICreate("MAC Address", 300, 100) ; Add a label to display the MAC address GUICtrlCreateLabel("Your MAC address: " & $sMAC, 10, 10, 280, 30) ; Show the GUI GUISetState() ; Wait for the user to close the window While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit WEnd Func _GetMACAddress() Local $sCommand = "getmac" Local $sResult = Run(@ComSpec & " /c " & $sCommand, "", @SW_HIDE, 1) ; Capture standard output Local $sOutput = StdoutRead($sResult) Return StringTrimRight($sOutput, 2) ; Trim the newline at the end EndFunc
SOLVE-SMART Posted Thursday at 10:17 PM Posted Thursday at 10:17 PM (edited) Hi @zoel 👋 , please try this function instead (an old one of mine): Func _GetMacOrIpAddress() Local Const $oWmiService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2') Local Const $oNetworkAdapters = $oWmiService.ExecQuery('select * from Win32_NetworkAdapterConfiguration where IPEnabled = True') For $oNetworkAdapter In $oNetworkAdapters If $oNetworkAdapter.MACAddress <> '' Then Return $oNetworkAdapter.MACAddress EndIf Next Return @IPAddress1 ; fallback EndFunc Best regards Sven Edited Thursday at 10:18 PM by SOLVE-SMART Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon)
Nine Posted 16 hours ago Posted 16 hours ago (edited) @zoel There is numerous issues in your code : 1- not enough space to display the result 2- best to use a fixed space font (to align columns) 3- wrong stream option in run command 4- no need to shell getmac 5- need to wait for process to end 6- undeclared variable (always use Opt("MustDeclareVars", True)) #include <Constants.au3> #include <GUIConstants.au3> Opt("MustDeclareVars", True) ; Get the MAC address Local $sMAC = _GetMACAddress() ; Create the GUI GUICreate("MAC Address", 700, 150) ; Add a label to display the MAC address GUICtrlCreateLabel("Your MAC address: " & $sMAC, 10, 10, 680, 130) GUICtrlSetFont(-1, 0, 0, 0, "FixedSys") ; Show the GUI GUISetState() ; Wait for the user to close the window Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _GetMACAddress() Local $iPID = Run("getmac", "", @SW_HIDE, $STDERR_MERGED) ; Capture standard output ProcessWaitClose($iPID) Local $sOutput = StdoutRead($iPID) Return StringTrimRight($sOutput, 2) ; Trim the newline at the end EndFunc ;==>_GetMACAddress Edited 16 hours ago by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
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