2013-02-19 128 views
2

我有一个报告的列表是什么使用程序集进行本地化。这些组件应放置在报告服务的安装路径中。部署的一项任务是将这些程序集复制到.Net(vb.net)的正确路径中。报告服务:获取报告服务路径

现在我们使用硬代码路径来添加程序集(与翻译)。那么,是否有某种方法可以获得来自Vb.Net的服务器中运行的sql报告服务的路径?

I.E.的reporing服务的有效路径是:

C:\ Program Files文件\ Microsoft SQL Server的\ MSRS10_50.MSSQLSERVER \ Reporting Services的\的ReportServer \ BIN

我所期望得到的是这样的:

C:\ Program Files文件\ Microsoft SQL Server的\ MSRS10_50.MSSQLSERVER \

回答

0

假设你的情况是一致的呐MED(MSRS10_50.MSSQLSERVER),检查SQLPath键在此注册表位置:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Setup

enter image description here

看看this SO post的帮助与读取注册表如果需要的话。

+0

感谢您的反馈:)。我可以假设这个键是相对于SQL2008R2 ..但其他版本呢? – Rolando 2013-02-19 23:39:57

+0

只需枚举HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft SQL Server中以“MSRS”开头并注册所有版本的注册表中的文件夹即可。 – Bryan 2013-02-19 23:47:39

0

好吧,我会糊,以分享我的代码:)(控制台VB.Net应用程序)

Private Const INSTANCES As String = "SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" 
Private PathToReplace As String = "SOFTWARE\Microsoft\Microsoft SQL Server\{textToReplace}\Setup" 

Sub Main() 

    'For now we must be sure we have only one instance of sql reporting service 
    Dim reportingInstances As List(Of String) = GetSQLReportingServicesInstances() 

    Dim InstanceName As String = GetKeyValue(INSTANCES, reportingInstances.Item(0)) 

    Dim registryPathOfSqlReportingServices As String = PathToReplace.Replace("{textToReplace}", InstanceName) 

    Dim pathOfSqlReportingServices As String = GetKeyValue(registryPathOfSqlReportingServices, "SQLPath") 

    Console.WriteLine(pathOfSqlReportingServices) 

    Console.ReadLine() 
End Sub 


Public Function GetKeyValue(ByVal RegistryPath As String, ByVal key As String) As String 

    Dim localMachine As RegistryKey = GetRegistryParentKey() 

    Dim windowsNTKey As RegistryKey = localMachine.OpenSubKey(RegistryPath) 

    Return windowsNTKey.GetValue(key).ToString() 

End Function 

Public Function GetSQLReportingServicesInstances() As List(Of String) 

    Dim listOfInstances As New List(Of String) 

    Dim localMachine As RegistryKey = GetRegistryParentKey() 

    Dim InstancesKey As RegistryKey = localMachine.OpenSubKey(INSTANCES) 

    For Each InstanceKey As String In InstancesKey.GetValueNames 
     listOfInstances.Add(InstanceKey) 
    Next 

    Return listOfInstances 

End Function 


Public Function GetRegistryParentKey() As RegistryKey 

    Dim localMachine As RegistryKey = Nothing 

    If (Environment.Is64BitOperatingSystem) Then 
     localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64) 
    Else 
     localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32) 
    End If 
    Return localMachine 

End Function