Jump to content
Sign in to follow this  
AlterMind

Capture hostname output directly ?

Recommended Posts

AlterMind

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.

Share this post


Link to post
Share on other sites
JLogan3o13

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
AlterMind

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 by AlterMind

Share this post


Link to post
Share on other sites
Chimp

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)

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
JLogan3o13

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))

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
iamtheky

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 by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×