2009-11-04 2 views

답변

1

다음은 2005/2008 코드입니다. 2000 년에는 내가 믿는 다른 곳에 저장되어 있기 때문에 레지스트리에 직접 들어가야합니다. 또한 테이블 변수에서 실제 임시 테이블로 변경해야합니다.

즐기십시오.

Declare @Instances Table 
(InstanceName SysName, RegKey SysName, InstanceType Character Varying(50), 
Version Character Varying(4), Features National Character Varying(2000)) 

Insert Into @Instances(InstanceName, RegKey) 
Execute Master.dbo.xp_RegEnumValues N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL' 
Update @Instances Set InstanceType = 'SQL Server' Where InstanceType Is Null 

Insert Into @Instances(InstanceName, RegKey) 
Execute Master.dbo.xp_RegEnumValues N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\RS' 
Update @Instances Set InstanceType = 'Reporting Services' Where InstanceType Is Null 

Insert Into @Instances(InstanceName, RegKey) 
Execute Master.dbo.xp_RegEnumValues N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\OLAP' 
Update @Instances Set InstanceType = 'Analysis Services' Where InstanceType Is Null 

Declare 
@More Bit, @CRegKey SysName, @RegPath National Character Varying(2000), 
@Features National Character Varying(2000), @VersionString National Character Varying(500) 

Declare CInstance Cursor 
For 
Select RegKey From @Instances 

Open CInstance 
Set @More = 1 

While (@More = 1) 
Begin 
Fetch Next From CInstance Into @CRegKey 
If (@@Fetch_Status != 0) 
    Set @More = 0 
Else 
    Begin 
    Set @RegPath = N'Software\Microsoft\Microsoft SQL Server\' + @CRegKey + '\Setup' 

    Execute Master.dbo.xp_RegRead N'HKEY_LOCAL_MACHINE', @RegPath, N'FeatureList', @Features Output, 'no_output' 
    Execute Master.dbo.xp_RegRead N'HKEY_LOCAL_MACHINE', @RegPath, N'PatchLevel', @VersionString Output, 'no_output' 
    -- \' ignore this, it's just to get the formatting right 
    Update @Instances 
    Set 
    Features = @Features, 
    Version = (Case When Left(@VersionString, 1) = '9' Then '2005' 
        When Left(@VersionString, 2) = '10' Then '2008' 
        Else '????' End) 
    Where Current Of CInstance 
    End 
End  

Close CInstance 
Deallocate CInstance 

Update @Instances Set InstanceName = '(local)' Where InstanceName = 'MSSQLServer' 

Select InstanceName, InstanceType, Version, Features 
From @Instances 
관련 문제