Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 



JSI Tip 10001. How can a script determine if the computer it is running on is a Standalone Workstation, Member Workstation, Standalone Server, Member Server, Backup Domain Controller, or Primary Domain Controller?

RSS
Subscribe to Windows IT Pro | See More Backup and Recovery Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!


10001 » How can a script determine if the computer it is running on is a Standalone Workstation, Member Workstation, Standalone Server, Member Server, Backup Domain Controller, or Primary Domain Controller? 23-Dec-05


I have scripted DomainRole.bat to determine which of the following roles describes the current computer:
Standalone Workstation
Member Workstation
Standalone Server
Member Server
Backup Domain Controller
Primary Domain Controller
The syntax for using DomainRole.bat is:

call DomainRole string

Where string is a call directed environment variable that will contain one of the following number-text strings:

0-Standalone Workstation
1-Member Workstation
2-Standalone Server
3-Member Server
4-Backup Domain Controller
5-Primary Domain Controller
DomainRole.bat contains:
@echo off
if {%1}=={} @echo Syntax: DomainRole Role&goto :EOF
setlocal
if exist "%TEMP%\DoomainRole.vbs" goto doit
@echo On Error Resume Next>"%TEMP%\DoomainRole.vbs"
@echo strComputer = ".">>"%TEMP%\DoomainRole.vbs"
@echo Set objWMIService = GetObject("winmgmts:\\" ^& strComputer ^& "\root\cimv2")>>"%TEMP%\DoomainRole.vbs"
@echo Set colItems = objWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem",,48)>>"%TEMP%\DoomainRole.vbs"
@echo For Each objItem in colItems>>"%TEMP%\DoomainRole.vbs"
@echo.  Wscript.Echo objItem.DomainRole>>"%TEMP%\DoomainRole.vbs"
@echo Next>>"%TEMP%\DoomainRole.vbs"
:doit
for /f "Tokens=*" %%r in ('cscript //nologo "%TEMP%\DoomainRole.vbs"') do (
 set /a role=1%%r -10
)
set /a role=%role% * 28
set table=0-Standalone Workstation    1-Member Workstation        2-Standalone Server         3-Member Server             4-Backup Domain Controller  5-Primary Domain Controller #
call set work=%%table:~%role%^,28%%#
set work=%work:  =%
set work=%work: #=%
set work=%work:#=%
endlocal&set %1=%work%



End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 24, 2008

An often irreverent look at some of the week's other news, including a Vista Capable dismissal request, Zune price reductions, Morrow musings, Novell and Microsoft sitting in a tree ... two years later, Yahoo!, IE 6 on Windows Mobile, and so much more ...


Related Events Virtualization Management

Virtualization 101

Creating the Business Case for Disaster Recovery Planning and Budgeting

Check out our list of Free Email Newsletters!

Related Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing