Enumerate SQL Server Names from "SQL Server Enterprise Manager" | Database Journal

Enumerate SQL Server Names from “SQL Server Enterprise Manager”

Jun 1, 2005
1 minute read

Occasionally, SQL
Server database administrators are requested to provide a list of development
SQL Servers, production SQL Servers and so on. Many articles, such as "Monitor
Disk Space on Multiple SQL Servers
"
and "Inventorying
hardware and OS information on all SQL Servers
"
require a list of
servers in a text file.

Usually
Database administrators do not have the list in hand or have never made a list,
but it is always available on the Enterprise manager since most of the servers
are registered in Enterprise Manager.

Servers
that are registered in Enterprise manager are stored in the registry of the
client machine. This article explains how to take advantage of Windows
Scripting Host and VBScript to read the registry in order to enumerate all of
the SQL servers that are registered in Enterprise Manager.

Pre-requisite

a. 
SQL Server 2000 Client is
installed on the machine where we are executing the script and most of the
servers are already registered in Enterprise manager.

b. 
VBScript and
WSH need the ability to be executed on the client machine.

Step 1

Create the folder C:\Scan
[Refer Fig 1.0]



Fig 1.0

Step 2

Download the VB Script
below and save it as C:\Scan\scanEM.vbs [Refer Fig 1.0]

Save this file to c:\scan\scanEM.vbsExecute it on the command propmtCreated by : MAKDate: March 18, 2005
Set objArgs = WScript.Arguments
GroupName= objArgs(0)
mySkey =SOFTWARE\Microsoft\Microsoft SQL Server\80\Tools\SQLEW\Registered Servers X& “\” & GroupName
Const HKCR=&H80000000HKEY_CLASSES_ROOT
Const HKCU=&H80000001HKEY_CURRENT_USER
Const HKLM=&H80000002HKEY_LOCAL_MACHINE
Const HKU=&H80000003HKEY_USERS
Const HKCC=&H80000005HKEY_CURRENT_CONFIG
Const REG_SZ=1
Const REG_EXPAND_SZ=2
Const REG_BINARY=3
Const REG_DWORD=4
Const REG_MULTI_SZ=7
Const KEY_QUERY_VALUE=&H1
Const KEY_SET_VALUE=&H2
Const KEY_CREATE_SUB_KEY=&H4
Const KEY_ENUMERATE_SUB_KEYS=&H8
Const KEY_NOTIFY=&H10
Const KEY_CREATE_LINK=&H20
Const DELETE=&H10000
Const READ_CONTROL=&H20000
Const WRITE_DAC=&H40000
Const WRITE_OWNER=&H80000
Set WshShell = WScript.CreateObject(WScript.Shell)
Set oReg=GetObject(winmgmts:!root/default:StdRegProv)wscript.echo EnumKey
  (HKCU,SOFTWARE\Microsoft\Microsoft SQL Server\80\Tools\SQLEW\Registered Servers X)wscript.echo “——————————–”
wscript.echo EnumValues(HKCU,myskey)********************     Function Name:          EnumKey*     Inputs:               Key, Subkey*     Example:           wscript.echo EnumKey(HKCU,Software\Microsoft)*     Returns:          List of all sub keys*******************
Function EnumKey(Key, SubKey)
     Dim Ret()
     oReg.EnumKey Key,SubKey, sKeys
     ReDim Ret(UBound(sKeys))
     For Count = 0 to UBound(sKeys)
          Ret(Count) = sKeys(Count)
     Next
     EnumKey = Join(Ret,vbCrLf)
End Function********************     Function Name:          EnumValues*     Inputs:               Key, Subkey*     Example           wscript.echo EnumValues(HKCU,Software\Microsoft)*     Returns:          List of all values in the format;*                         NAME,TYPE,VALUE*******************
Function EnumValues(Key, SubKey)
     Dim Ret()
     oReg.EnumValues Key,SubKey, sKeys, iKeyTypefill the array
     ReDim Ret(UBound(sKeys))
     For Count = 0 to UBound(sKeys)
          Select Case iKeyType(Count)
               Case REG_SZ
                    oReg.GetStringValue Key,SubKey, sKeys(Count), sValue
                    Ret(Count) = sKeys(Count) &,&REG_SZ&,& sValue
               Case REG_EXPAND_SZ
                    oReg.GetExpandedStringValue Key,SubKey, sKeys(Count), sValue
                    Ret(Count) = sKeys(Count) &,&REG_EXPAND_SZ&,& sValue
               Case REG_BINARY
                    oReg.GetBinaryValue Key,SubKey, sKeys(Count), aValue
                    Ret(Count) = sKeys(Count)&,&REG_BINARY&,& Join(aValue,””)
               Case REG_DWORD
                    oReg.GetDWORDValue Key,SubKey, sKeys(Count), lValue
                    Ret(Count) = sKeys(Count) &,&REG_DWORD&,& lValue
               Case REG_MULTI_SZ
                    oReg.GetMultiStringValue Key,SubKey, sKeys(Count), sValue
                    Ret(Count) = sKeys(Count) &,&REG_MULTI_SZ&,& Join(sValue,””)
          End Select
     Next
     EnumValues = Join(Ret,vbCrLf)
End Function

Download scanEM.vbs_.

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.