Sign in to follow this  
Followers 0
bourny

How to detect domain name

7 posts in this topic

I am running a script that checks whet domain the machine is part of. This will tell me if the machine is on its own workgroup p.c name or actually part of a domain .

I have tried

@LogonDNSDomain Logon DNS Domain.

@LogonDomain Logon Domain.

@LogonServer Logon server.

If I am part of a domain called Mydomain.co.uk and log into the machine as a local machine account against the local machine name called "Computer1" the above commands will show "Computer1" "not Mydomain.co.uk"

I am looking for a way to find which domain the computer is connected to regardless what it is currently logged in as. I have found some registry areas that state the name of the domain I am looking for but not sure of the consistency of these keys across other platforms....

Keys I found

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\History

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DNSRegisteredAdapters\{9C4CD23B-3AF0-4897-BE2A-3E3E2633FD28}

Is there a function / Macro that I am missing in Autoit that I would prefer to use similar to what @LogonDomain would give out

Thanks

Share this post


Link to post
Share on other sites



$ComputerDomain = _DomainComputerBelongs()
MsgBox(0 , @LogonDomain , 'Domain: ' & $ComputerDomain)

Func _DomainComputerBelongs($strComputer = "localhost")
    ; Generated by AutoIt Scriptomatic
    $Domain = ''
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20

    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    If Not IsObj($objWMIService) Then Return SetError(1, 0, '')
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            $Domain = $objItem.Domain
        Next
    Endif
    Return $Domain
EndFunc


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Easy way:

$read = RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName")
If $read <> "" Then MsgBox(0, "Info", "Domain name is: " & $read)

;)

Share this post


Link to post
Share on other sites

Thanks,,,,

I had already identified in the first post I can just read the registry - This is fine however does not provide me with 100% consistency as these values can and have been changed in my scripts especially in the winlogon part of the registry for auto logins etc.

I prefer to pull the information in a more structured way ....

I think going down APi is the way with objects....

Thanks for your responses...

Share this post


Link to post
Share on other sites

Thanks,,,,

I had already identified in the first post I can just read the registry - This is fine however does not provide me with 100% consistency as these values can and have been changed in my scripts especially in the winlogon part of the registry for auto logins etc.

I prefer to pull the information in a more structured way ....

I think going down APi is the way with objects....

Thanks for your responses...

Try the script from post #2 at work we have two domain with one way trust, depending in which domain the computer is assign to my script runas using different credentials.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try this too.

Msgbox(0,GetRootDSE(),FriendlyRootDSE(GetRootDSE()))

Func GetRootDSE()
    $RootDSE = ObjGet("LDAP://RootDSE")
    If IsObj($RootDSE) Then Return $RootDSE.get( "DefaultNamingContext" )
EndFunc

Func FriendlyRootDSE($strRootDSE)
    $strRootDSE = StringReplace($strRootDSE,"DC=","")
    $strRootDSE = StringReplace($strRootDSE,",",".")
    Return $strRootDSE
EndFunc
Edited by spudw2k

Share this post


Link to post
Share on other sites

Try the script from post #2 at work we have two domain with one way trust, depending in which domain the computer is assign to my script runas using different credentials.

Thanks....

will be using this script to do what I need to achieve..... I prefer this sort of structured script rather than a registry pull....

Will also test this other script from spudw2k....

Thanks again for your input

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  
Followers 0