2013-02-19 100 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