2

I have a list of reports what are using assemblies to be localized. Theses assemblies should be placed on the installation path of reporting services. One task of deployment is copy these assemblies in the right path from .Net (vb.net).

For now we are using hard code path in order add the assemblies (with the translations). So, is there some way to get the path of sql reporting service what is runing in the server from Vb.Net?

I.E. a valid path of reporing services is:

C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin

what I expect to get is something like:

C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Rolando
  • 752
  • 1
  • 14
  • 41

2 Answers2

0

Assuming your instances are consistently named (MSRS10_50.MSSQLSERVER), check the SQLPath key in this registry location:

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

enter image description here

Take a look at this SO post for help with reading registry if needed.

Community
  • 1
  • 1
Bryan
  • 17,112
  • 7
  • 57
  • 80
  • thank you for your feedback:). I could suppose that this key is relative to SQL2008R2.. but what about other versions? – Rolando Feb 19 '13 at 23:39
  • Just enumerate folders in the registry under `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft SQL Server` that start with `MSRS` and that should take care of all versions. – Bryan Feb 19 '13 at 23:47
0

Okay i will paste my code in order to share it :) (Console VB.Net application)

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
Rolando
  • 752
  • 1
  • 14
  • 41