Determine if the current pc is part of a domain? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Posts: 34
Joined: 11 Aug 2016, 11:31

Determine if the current pc is part of a domain?

22 Sep 2016, 05:02


is there a method to determine if the current pc you're working on is part of a Windows Active Directory domain?
A simple true / false would be sufficient, no further information is needed (what is the name of the Domain Controller you're authenticated with or anything like that)...
User avatar
Posts: 2681
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: Determine if the current pc is part of a domain?  Topic is solved

22 Sep 2016, 06:01

Code: Select all

MsgBox % NetGetJoinInformation()

    DllCall("netapi32.dll\NetGetJoinInformation", "ptr", 0, "ptr*", name, "int*", type)
    return type, DllCall("netapi32.dll\NetApiBufferFree", "ptr", name)


Return Codes

NetSetupUnknownStatus  -> 0    (The status is unknown.)
NetSetupUnjoined       -> 1    (The computer is not joined.)
NetSetupWorkgroupName  -> 2    (The computer is joined to a workgroup.)
NetSetupDomainName     -> 3    (The computer is joined to a domain.)
[AHK] x64 Unicode | [WIN] 10 Pro (Version 20H2) x64 | [GitHub] Profile
Donations are appreciated if I could help you
Posts: 7200
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Determine if the current pc is part of a domain?

23 Sep 2016, 03:30

Here's another way:

Code: Select all

for pc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_ComputerSystem")
    if pc.PartOfDomain
        MsgBox % pc.Name " is in domain " pc.Domain
        MsgBox % pc.Name " is not in a domain"
It may be worth familiarising yourself with WMI. You can get a lot of other useful information just by taking this code and replacing the class name (Win32_ComputerSystem) and property names (PartOfDomain, Name, Domain).

You can not only query information, but also make changes, such as by calling pc.UnjoinDomainOrWorkgroup(...).

Return to “Ask For Help”

Who is online

Users browsing this forum: ark, nutnutwin and 30 guests