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

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

Determine if the current pc is part of a domain?

22 Sep 2016, 05:02

Hi,

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
jNizM
Posts: 2681
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

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

22 Sep 2016, 06:01

Code: Select all

MsgBox % NetGetJoinInformation()

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

/* https://msdn.microsoft.com/en-us/library/aa370423(v=vs.85).aspx

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] 1.1.33.02 x64 Unicode | [WIN] 10 Pro (Version 20H2) x64 | [GitHub] Profile
Donations are appreciated if I could help you
lexikos
Posts: 7201
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
    else
        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: Bing [Bot], Dinarid, TAC109, the_body and 46 guests