誰かがそれを必要とする場合に備えて、私は機能しているコードを追加します:)
Public Shared Function GetSqlPath(ByVal connectionstring As String) As String
Dim rowCount = 0
Using sqlConn As New SqlConnection(connectionstring)
Using cmd As New SqlCommand("xp_instance_regread", sqlConn)
cmd.CommandType = CommandType.StoredProcedure
Dim parameterRootKey As New SqlParameter With {.SqlDbType = SqlDbType.NVarChar,
.ParameterName = "@rootkey",
.Size = 128,
.Direction = ParameterDirection.Input, .Value = "HKEY_LOCAL_MACHINE"
}
Dim parameterKey As New SqlParameter With {.SqlDbType = SqlDbType.NVarChar,
.ParameterName = "@key",
.Size = 128,
.Direction = ParameterDirection.Input,
.Value = "SOFTWARE\Microsoft\MSSQLSERVER\Setup"
}
Dim parameterValueName As New SqlParameter With {.SqlDbType = SqlDbType.NVarChar,
.ParameterName = "@value_name",
.Size = 128,
.Direction = ParameterDirection.Input, .Value = "SQLPath"
} '
Dim parameterValue As New SqlParameter With {.SqlDbType = SqlDbType.NVarChar,
.ParameterName = "@value",
.Size = 128,
.Direction = ParameterDirection.Output
}
cmd.Parameters.Add(parameterRootKey)
cmd.Parameters.Add(parameterKey)
cmd.Parameters.Add(parameterValueName)
cmd.Parameters.Add(parameterValue)
sqlConn.Open()
cmd.ExecuteNonQuery()
Return CType(parameterValue.Value, String)
End Using
End Using