Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determine if Workgroup or Domain?

6 views
Skip to first unread message

Todd Brooks

unread,
Apr 8, 2003, 2:22:26 PM4/8/03
to
Win32_ComputerSystem.PartOfDomain has this information, but according to the
docs, it is only for Windows XP and Windows .NET 2003 Server.

Is there a way (even API) to determine if the computer (Win9x, WinNT, Win2k,
etc) is part of a domain or workgroup? tia

Regards,

todd


Torgeir Bakken (MVP)

unread,
Apr 8, 2003, 6:48:35 PM4/8/03
to
Todd Brooks wrote:

Hi

I use Netdom.exe v1.8 for this (you can't use any newer version than v1.8 in the
script below, note that I have renamed netdom.exe to netdom18.exe as well). Will
work for NT4, Win2k and WinXP.


Netdom.exe version 1.8 dated 30. June 1999 can be downloaded from the following
Microsoft FTP site:

ftp://ftp.microsoft.com/reskit/nt4/x86/
self extracting zip file file: netdom_x86.exe

' Script start

If IsDomainMember() Then
WScript.Echo "Domain member"
Else
WScript.Echo "Workgroup member"
End if

Function IsDomainMember
' Returns True or False based on the output from netdom v1.8
'
' Author: Torgeir Bakken
' Works on NT 4, Win2k and WinXP

' path to netdom v1.8
sSourcePath = "c:\util\netdom18.exe"

Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\resultnetdom.tmp"

oShell.Run "%comspec% /C " & sSourcePath & _
" MEMBER \\%computername% /QUERY >" & sTempFile, 0, True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)

sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)

Select Case InStr(sResults,"is member of the domain")
Case 0 IsDomainMember = False
Case Else IsDomainMember = True
End Select
End Function


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Todd Brooks

unread,
Apr 8, 2003, 9:16:43 PM4/8/03
to
Is there a programmatic, no-dependency solution available? Does WMI hold
this information?

Regards,

todd

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3E9351C3...@hydro.com...

Jian-Shen Lin[MS]

unread,
Apr 10, 2003, 4:23:23 AM4/10/03
to
NetGetJoinInformation

The NetGetJoinInformation function retrieves join status information for
the specified computer.

[out] Receives the join status of the specified computer. This parameter
can have one of the following values.
typedef enum _NETSETUP_JOIN_STATUS {

NetSetupUnknownStatus = 0,
NetSetupUnjoined,
NetSetupWorkgroupName,
NetSetupDomainName

} NETSETUP_JOIN_STATUS, *PNETSETUP_JOIN_STATUS;


Best Regards

Jian Shen

This posting is provided "AS IS" with no warranties, and confers no rights.

Todd Brooks

unread,
Apr 11, 2003, 12:52:17 AM4/11/03
to
According to the documentation, this API requires Windows XP and later
operating systems.

Is there an equivalent that will work across all Windows platforms (Windows
9x/ME/NT/2k/XP)?

Regards,

todd

"Jian-Shen Lin[MS]" <js...@online.microsoft.com> wrote in message
news:uWC15pz$CHA....@cpmsftngxa06.phx.gbl...

Tianxiang Zhang

unread,
Apr 11, 2003, 11:54:01 AM4/11/03
to
The Win32_ComputerSystem.DomainRole should solve your
problem for Windows 2000.

>.
>

Torgeir Bakken (MVP)

unread,
Apr 11, 2003, 3:46:32 PM4/11/03
to
Tianxiang Zhang wrote:

> Todd Brooks wrote:
> >Win32_ComputerSystem.PartOfDomain has this information,
> > but according to the
> >docs, it is only for Windows XP and Windows .NET 2003
> > Server.
> >
> >Is there a way (even API) to determine if the computer
> > (Win9x, WinNT, Win2k,
> > etc) is part of a domain or workgroup? tia
>

> The Win32_ComputerSystem.DomainRole should solve your
> problem for Windows 2000.

Hi

Yes :-)

Modified function IsDomainMember that uses WMI:


sComputer = "." ' use "." for local computer

If IsDomainMember(sComputer) Then


WScript.Echo "Domain member"
Else
WScript.Echo "Workgroup member"
End if

Function IsDomainMember(Node)
' Returns True or False based on Win32_ComputerSystem.DomainRole
'
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & Node & "\root\cimv2")
Set colComputer = oWMI.ExecQuery _
("Select DomainRole from Win32_ComputerSystem")
For Each oComputer in colComputer
iDR = oComputer.DomainRole
Next

If iDR = 0 Or iDR = 2 Then
IsDomainMember = False
Else
IsDomainMember = True
End If

Todd Brooks

unread,
Apr 11, 2003, 4:02:52 PM4/11/03
to
thank you.

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message

news:3E971B97...@hydro.com...

0 new messages