JSI Tip 2999. How do I determine the workgroup name in a peer-to-peer network?


When you logon to a domain, both Windows NT 4.0 and Windows 2000 (Windows NT 5.0) provide the following environment variables, which you can see by typing SET at a CMD prompt:

COMPUTERNAME - The computer name.
USERNAME     - The UserID.
LOGONSERVER  - The authenticating domain controller ComputerName, preceeded with a \\.
USERDOMAIN   - The downlevel domain name (Windows NT 4.0 style).
When you logon onto a workgroup (peer-to-peer), both operating systems provide:
COMPUTERNAME - The computer name.
USERNAME     - The UserID.
LOGONSERVER  - The authenticating computer, preceeded with a \\. This is the local machine.
USERDOMAIN   - This is always the local ComputerName.
Neither operating system provides the workgroup name when logging onto a peer-to-peer network.

You can see the workgroup name by issuing the following CMD:

Net Config Workstation

NOTE: The Workstation Domain line shows the workgroup name.

NOTE: When you are logged onto a domain, this line displays the downlevel domain name.

To define a WORKGROUP environment variable, for the current CMD session, create WORGROUP.BAT, which contains:

@Echo Off
For /F "tokens=3" %%i in ('Net Config Workstation^|Find /i "Workstation Domain  "') Do @Set WORKGROUP=%%i
If you wish to have this environment variable available thoughout the logged on user session, use SETX.EXE from the Windows 2000 Resource Kit or Supplement 4 of the Windows NT 4.0 Resource Kit.

To also set WORKGROUP into the user environment, WORGROUP.BAT would contain:

@Echo Off
For /F "tokens=3" %%i in ('Net Config Workstation^|Find /i "Workstation Domain  "') Do  @Set WORKGROUP=%%i&SETX WORKGROUP %%i
NOTE: There appears to be a bug in Windows 2000 SP1. While any environment variable set with SETX.EXE is NOT available in the current CMD session, it should be available in future sessions, but it isn't, until the user logs off/on.


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish