'Save this file to c:\scan\scanEM.vbs 'Execute it on the command propmt 'Created by : MAK 'Date: 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=&H80000000 'HKEY_CLASSES_ROOT Const HKCU=&H80000001 'HKEY_CURRENT_USER Const HKLM=&H80000002 'HKEY_LOCAL_MACHINE Const HKU=&H80000003 'HKEY_USERS Const HKCC=&H80000005 'HKEY_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, iKeyType 'fill 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