Domain Registry Key??

M

Mark

I need to know what registry key will accurately
represent what domain a MACHINE is associated to, even
when a user logs on to the machine locally.

Any help would be very much appreciated! Thank you for
your help!!!!

- Mark
 
T

Torgeir Bakken \(MVP\)

Mark said:
I need to know what registry key will accurately
represent what domain a MACHINE is associated to, even
when a user logs on to the machine locally.

Any help would be very much appreciated! Thank you for
your help!!!!
Hi

As far as I know, there is no "safe" place in registry to read this from.

Parse the output from "net.exe config workstation" in a batch file, or
use VBScript/WMI.


Batch file (do *not* remove the spaces in "workstation domain "):

'--------------------8<----------------------
@echo off
for /f "tokens=3" %%a in (
'net.exe config workstation^|find.exe /i "workstation domain "') do set domain=%%a
echo %domain%
'--------------------8<----------------------



VBScript/WMI:

'--------------------8<----------------------
sNode = "." ' use "." for local computer
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sNode & "\root\cimv2")
Set colComputer = oWMI.ExecQuery _
("Select DomainRole, Domain from Win32_ComputerSystem")
For Each oComputer in colComputer
iDR = oComputer.DomainRole
sName = oComputer.Domain
Next

If iDR = 0 Or iDR = 2 Then
WScript.Echo "Computer is in workgroup " & sName
Else
WScript.Echo "Computer is in domain " & sName
End If
'--------------------8<----------------------
 
T

Torgeir Bakken \(MVP\)

Mark said:
I need to know what registry key will accurately
represent what domain a MACHINE is associated to, even
when a user logs on to the machine locally.

Any help would be very much appreciated! Thank you for
your help!!!!
Hi

As far as I know, there is no "safe" place in registry to read this from.

Parse the output from "net.exe config workstation" in a batch file, or
use VBScript/WMI.


Batch file (do *not* remove the spaces in "workstation domain "):

'--------------------8<----------------------
@echo off
for /f "tokens=3" %%a in (
'net.exe config workstation^|find.exe /i "workstation domain "') do set domain=%%a
echo %domain%
'--------------------8<----------------------



VBScript/WMI:

'--------------------8<----------------------
sNode = "." ' use "." for local computer
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sNode & "\root\cimv2")
Set colComputer = oWMI.ExecQuery _
("Select DomainRole, Domain from Win32_ComputerSystem")
For Each oComputer in colComputer
iDR = oComputer.DomainRole
sName = oComputer.Domain
Next

If iDR = 0 Or iDR = 2 Then
WScript.Echo "Computer is in workgroup " & sName
Else
WScript.Echo "Computer is in domain " & sName
End If
'--------------------8<----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top