Question

How can I access DSN list from client machine using ASP.Net web application? is it even possible or not?

On local development server, it works fine and I can achieve it but what about live server? There are so many security concerns now a days which will not allowed to access registry on client machine to any web application.

Any way to access registry "ODBC Data Sources" of client machine through asp.net application? And if there is any work around to achieve this, please let me know about it?

Was it helpful?

Solution

Couldn't get enough time to update solution for this problem. I was following some real tight schedule.

but here we go.

First of all,

You can not access any documents/files from Client machine without any user interventions. Period.

Fairly because of Security Issues and its quite understandable.

Even though if you want to achieve it any how, then VBScript will be the best solution that will come handy.

Just posting the VBScript code to read ODBC DSN list entries from client system and store it in an XML file, if anyone is interested in future.

option explicit

        const HKLM = &H80000001

        dim keyPath, subKeyPath
        keyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
        subKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"

        dim reg, subReg

        dim valueNames, types, arrValueNames, arrValueTypes
        dim subValueNames, subArrValueNames, subArrValueTypes

        dim value
        value = "SQL Server"
        dim subValue
        subValue = "server"
        dim i, k

        'Create XML file from this where we'll be storing ODBC Connections Parameters
        dim xmlDoc, objRoot, objName, objServerName, objDBName, objIntro
        Set xmlDoc = _
            CreateObject("Microsoft.XMLDOM")

        'DBDetails element
        Set objRoot = _
            xmlDoc.createElement("DBDetails")  
        xmlDoc.appendChild objRoot

        set reg = getObject( "Winmgmts:root\default:StdRegProv" )

        reg.EnumValues HKLM, keyPath, arrValueNames, arrValueTypes

            For i = 0 to Ubound(arrValueNames)
                valueNames = arrValueNames(i)
                reg.GetStringValue HKLM, keyPath, valueNames, value    

                IF value = "SQL Server" THEN

                    'Create Element for this DB and add values as sub nodes
                        Set objName = _
                            xmlDoc.createElement("DB" & i)
                        objRoot.appendChild objName

                    set subReg = getObject( "Winmgmts:root\default:StdRegProv" )
                    subReg.EnumValues HKLM, "SOFTWARE\ODBC\ODBC.INI\" & valueNames, subArrValueNames, subArrValueTypes

                    for k = 0 to Ubound(subArrValueNames)
                        subValueNames = subArrValueNames(k)
                        reg.GetStringValue HKLM, "SOFTWARE\ODBC\ODBC.INI\" & valueNames, subValueNames, subValue    
                        'Wscript.Echo subValueNames & " -- " & subValue

                        'Server Name Node
                        If subValueNames = "Server" Then
                            Set objServerName = _
                                xmlDoc.createElement("ServerName")
                            objServerName.Text = subValue
                            objName.appendChild objServerName
                        End If

                        'DB Name Node
                        If subValueNames = "Database" Then
                            Set objDBName = _
                                xmlDoc.createElement("DatabaseName")
                            objDBName.Text = subValue
                            objName.appendChild objDBName
                        End If
                    Next
                End If
            Next

            Set objIntro = _
                xmlDoc.createProcessingInstruction _
                ("xml","version='1.0'")  
            xmlDoc.insertBefore _
                objIntro,xmlDoc.childNodes(0)


            If(WScript.CreateObject("Scripting.FileSystemObject").FolderExists("C:\TravcomTouch") = False) Then
                WScript.CreateObject("Scripting.FileSystemObject").CreateFolder("C:\TravcomTouch")
            End If
            xmlDoc.Save "C:\Test\ODBCDBDetails.xml"

Hope it will be helpful to someone !!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top