AlterMind Posted August 29, 2014 Posted August 29, 2014 I would like to find, if possible of course, the AutoIt statement that would collect in a $variable the output of the command "hostname" (executable located in system32 btw). Before AutoIt (in my batch file period) I would redirect its output to a file but I would like to avoid that inelegant method (that if possible again). I saw so far no possibilities with the Run nor the ShellExecute commands, but tbh I'm only an AutoIt newbie I've however found the registry key that seems to hold that value, via the following statement: $var=RegRead("HKEY_LOCAL_MACHINESYSTEMControlSet001servicesTcpipParameters", "Hostname") But I'm really curious to know if what I wanted to do initially is possible ? Thanks for your inputs ! PS: nope, I'm not interested in fetching the computername (e.g. @COMPUTERNAME) as this is not exactly the same thing.
Moderators JLogan3o13 Posted August 29, 2014 Moderators Posted August 29, 2014 The stated properties of the Hostname command state that it returns the host name portion of the full computer name. Can you please explain how that is different from the @ComputerName macro? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
AlterMind Posted August 29, 2014 Author Posted August 29, 2014 (edited) On 8/29/2014 at 1:21 PM, JLogan3o13 said: The stated properties of the Hostname command state that it returns the host name portion of the full computer name. Can you please explain how that is different from the @ComputerName macro? The @ComputerName (as the %COMPUTERNAME¨% environment variable which I understood it fetches) is seemingly always in full caps. The hostname may not only contain small caps (is the case on all my computers) but also spaces (if I remember right, but never used) and accents (which I used also but clearly try to avoid) and special characters. Edited August 29, 2014 by AlterMind
Gianni Posted August 29, 2014 Posted August 29, 2014 try this #include <AutoItConstants.au3> Local $pid = Run(@ComSpec & " /c " & 'hostname.exe', "", @SW_HIDE,$STDERR_MERGED), $output While not @error $output &= StdoutRead($pid) WEnd MsgBox(0,"output of hostname.exe",$output) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Moderators JLogan3o13 Posted August 29, 2014 Moderators Posted August 29, 2014 I tried this on several machines, with underscore and another with other special characters. Seems to get what you're looking for: MsgBox(0, "", StringLower(@ComputerName)) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
iamtheky Posted August 29, 2014 Posted August 29, 2014 (edited) or WMI via UEZ: )'> (my slow ass way using 'ping -a' is at the bottom of that thread, but that effort was purely academic) MsgBox(0, "Test", WMI_DNSHostName("localhost")) Func WMI_DNSHostName($srv) Local $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $srv & "\root\cimv2") Local $DNSHostName, $colItems, $colItem, $ping $ping = Ping($srv) If $ping Then $colItems = $objWMIService.ExecQuery("SELECT DNSHostName FROM Win32_ComputerSystem", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $DNSHostName = $objItem.DNSHostName Next SetError(0) Return $DNSHostName Else SetError(1) Return "Error!" EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc Edited August 29, 2014 by boththose Reveal hidden contents ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
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