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
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
Regards,
todd
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3E9351C3...@hydro.com...
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.
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...
>.
>
> 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
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3E971B97...@hydro.com...