从 Windows 2003 计算机导出 ODBC 系统 DSN?

发布于 2024-10-16 02:43:01 字数 47 浏览 1 评论 0原文

有没有办法从 Windows 2003 计算机导出所有 ODBC 系统 DSN?

Is there a way to export all the ODBC System DSNs from a windows 2003 machine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

鯉魚旗 2024-10-23 02:43:01

系统 DSN 信息存储在 HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI 注册表项下。您可以将该密钥导出到 .reg 文件并导入到另一台计算机上。

更新:

您也可以通过编程方式完成此操作。以下是一些示例:

http://www.codeproject.com/KB/database/DSNAdmin .aspx

http://support.microsoft.com/kb/110507

http://blogs.technet.com/b/heyscriptingguy/archive/2004/11/10/can-i-create-and-delete-a-dsn-using-a-script.aspx

System DSN information is stored under the HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI registry key. You could export that key to a .reg file and import on another machine.

UPDATE:

You can also do it programmatically. Here are a few examples:

http://www.codeproject.com/KB/database/DSNAdmin.aspx

http://support.microsoft.com/kb/110507

http://blogs.technet.com/b/heyscriptingguy/archive/2004/11/10/can-i-create-and-delete-a-dsn-using-a-script.aspx

把昨日还给我 2024-10-23 02:43:01

我刚刚自己使用一个非常简单的 bat 脚本完成了此操作,适用于 32 位 ODBC 源

regedit /e c:\backup\odbc.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI"

和 64 位源,或者如果您使用的是 32 位操作系统:

regedit /e c:\backup\odbc.reg "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI"

这会备份所有 DSN,但是您可以指定所需的 DNS。

I have just done this myself with a very simple bat script for 32bit ODBC sources

regedit /e c:\backup\odbc.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI"

and for the 64bit sources or if you are on a 32bit operating system:

regedit /e c:\backup\odbc.reg "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI"

This backs up all of the DSN's however you could then specify the DNS you want.

别靠近我心 2024-10-23 02:43:01

系统 DSN 存储在 HKLM\Software\ODBC\ODBC.INI 节点下的 Windows 注册表中
因此,如果您将此节点导出到 *.reg 文件并在目标计算机上运行此 reg 文件,它应该可以工作。

唯一的事情是,这个 reg 文件将包含一些可能特定于计算机的文件路径,例如
c:\WINNT\System32\bla-bla-bla.dll 包含 WINNT 文件夹,该文件夹在目标计算机上可能被称为 WINDOWS。因此,您需要花一些时间来确保 *.reg 文件中的所有路径对于您最终导入的目标计算机都是正确的。

System DSN's are stored in windows registry under HKLM\Software\ODBC\ODBC.INI node
So if you export this node to a *.reg file and run this reg file on a target machine, it should work.

The only thing, this reg file will contain some file paths which maybe computer specific, eg
c:\WINNT\System32\bla-bla-bla.dll includes WINNT folder which on target machine may be called like WINDOWS. So you will need to spend a bit time to make sure all paths in *.reg file are correct for target machine where you would finally import.

完美的未来在梦里 2024-10-23 02:43:01

我编写了一些 Powershell 函数,用于将 ODBC 连接从一台计算机复制到另一台计算机,它们发布(并不断更新)于:

http://powershell.com/cs/media/p/32510.aspx

# Usage:  
# $srcConfig = Get-OdbcConfig srcComputerName   
# Import-OdbcConfig trgComputerName $scrConfig  
# Only returns data when setting values  

function Get-OdbcConfig {  
param( $srcName )  
    if ( Test-Connection $srcName -Count 1 -Quiet ) {  
        # cycle through the odbc and odbc32 keys  
        $keys = "SOFTWARE\ODBC\ODBC.INI", "SOFTWARE\Wow6432Node\ODBC\ODBC.INI"  
        foreach ( $key in $keys ){  
            # open remote registry  
            $type = [Microsoft.Win32.RegistryHive]::LocalMachine  
            $srcReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( $type, $srcName )  
            $OdbcKey = $srcReg.OpenSubKey( $key )  
            # red through each key  
            foreach ( $oDrvr in $OdbcKey.GetSubKeyNames() ){  
                # form the key path  
                $sKey = $key + "\" + $oDrvr  
                $oDrvrKey = $srcReg.OpenSubKey( $sKey )  
                # cycle through each value, capture the key path, name, value and type  
                foreach ( $oDrvrVal in $oDrvrKey.GetValueNames() ) {  
                        $regObj = New-Object psobject -Property @{  
                        Path = $sKey  
                        Name = $oDrvrVal  
                        Value = $oDrvrKey.GetValue( $oDrvrVal )  
                        Type = $oDrvrKey.GetValueKind( $oDrvrVal )  
                    }  
                # dump each to the console  
                $regObj  
                }  
            }  
        }  
    }  
    # can't ping  
    else { Write-Host "$srcName offline" }  
}  

function Import-OdbcConfig {  
param( $trgName, $srcConfig )  
    if ( Test-Connection $trgName -Count 1 -Quiet ) {  
        # open remote registry  
        $type = [Microsoft.Win32.RegistryHive]::LocalMachine  
        $trgReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( $type, $trgName )  
        # sort out the key paths and cycle through each  
        $paths = $srcConfig | select -Unique Path  
        foreach ( $key in $paths ){  
            # check for the key and create it if it's not there  
            if ( ! $trgReg.OpenSubKey( $key.Path ) ) { $writeKey = $trgReg.CreateSubKey( $key.Path ) }  
            # open the path for writing ($true)  
            $trgKey = $trgReg.OpenSubKey( $key.Path, $true )  
            # cycle through each value, check to see if it exists, create it if it doesn't  
            foreach ( $oDrvr in $srcConfig | where { $_.Path -eq $key.Path } ) {  
                if ( ! $trgKey.GetValue( $oDrvr.Name ) ) {  
                    $oType = $oDrvr.Type  
                    $writeValue = $trgKey.SetValue( $oDrvr.Name, $oDrvr.Value, [Microsoft.Win32.RegistryValueKind]::$oType  )  
                    $objObj = new-object psobject -Property @{  
                        Path = $oDrvr.Path  
                        Name = $oDrvr.Name  
                        Value = $trgKey.GetValue( $oDrvr.Name )  
                        Type = $trgKey.GetValueKind( $oDrvr.Name )  
                    }  
                }  
            $objObj  
            }  
        }  
    }  
    # can't ping  
    else { Write-Host "$srcName offline" }  
} 

结合使用这些函数,您可以将一台计算机的所有 ODBC 连接复制到另一台计算机:

$srcConfig = Get-OdbcConfig srcComputerName
Import-OdbcConfig trgComputerName $scrConfig

通过过滤路径,可以仅包含您最喜欢的 ODBC 连接:

Import-OdbcConfig trgComputerName ( $scrKeys | where { $_.Path -eq "SOFTWARE\ODBC\ODBC.INI\GoodDatabase" } )

或过滤掉您不喜欢的 ODBC 连接:

Import-OdbcConfig trgComputerName ( $scrKeys | where { $_.Path -ne "SOFTWARE\ODBC\ODBC.INI\DatabaseIHate" } )

Import-OdbcConfig 仅在设置值时返回数据,或者无法 ping 目标(如果存在)没有什么可以创造它不会说什么。

I wrote some Powershell functions for copying ODBC connections from one computer to another, they are posted (and kept updated) at:

http://powershell.com/cs/media/p/32510.aspx

# Usage:  
# $srcConfig = Get-OdbcConfig srcComputerName   
# Import-OdbcConfig trgComputerName $scrConfig  
# Only returns data when setting values  

function Get-OdbcConfig {  
param( $srcName )  
    if ( Test-Connection $srcName -Count 1 -Quiet ) {  
        # cycle through the odbc and odbc32 keys  
        $keys = "SOFTWARE\ODBC\ODBC.INI", "SOFTWARE\Wow6432Node\ODBC\ODBC.INI"  
        foreach ( $key in $keys ){  
            # open remote registry  
            $type = [Microsoft.Win32.RegistryHive]::LocalMachine  
            $srcReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( $type, $srcName )  
            $OdbcKey = $srcReg.OpenSubKey( $key )  
            # red through each key  
            foreach ( $oDrvr in $OdbcKey.GetSubKeyNames() ){  
                # form the key path  
                $sKey = $key + "\" + $oDrvr  
                $oDrvrKey = $srcReg.OpenSubKey( $sKey )  
                # cycle through each value, capture the key path, name, value and type  
                foreach ( $oDrvrVal in $oDrvrKey.GetValueNames() ) {  
                        $regObj = New-Object psobject -Property @{  
                        Path = $sKey  
                        Name = $oDrvrVal  
                        Value = $oDrvrKey.GetValue( $oDrvrVal )  
                        Type = $oDrvrKey.GetValueKind( $oDrvrVal )  
                    }  
                # dump each to the console  
                $regObj  
                }  
            }  
        }  
    }  
    # can't ping  
    else { Write-Host "$srcName offline" }  
}  

function Import-OdbcConfig {  
param( $trgName, $srcConfig )  
    if ( Test-Connection $trgName -Count 1 -Quiet ) {  
        # open remote registry  
        $type = [Microsoft.Win32.RegistryHive]::LocalMachine  
        $trgReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( $type, $trgName )  
        # sort out the key paths and cycle through each  
        $paths = $srcConfig | select -Unique Path  
        foreach ( $key in $paths ){  
            # check for the key and create it if it's not there  
            if ( ! $trgReg.OpenSubKey( $key.Path ) ) { $writeKey = $trgReg.CreateSubKey( $key.Path ) }  
            # open the path for writing ($true)  
            $trgKey = $trgReg.OpenSubKey( $key.Path, $true )  
            # cycle through each value, check to see if it exists, create it if it doesn't  
            foreach ( $oDrvr in $srcConfig | where { $_.Path -eq $key.Path } ) {  
                if ( ! $trgKey.GetValue( $oDrvr.Name ) ) {  
                    $oType = $oDrvr.Type  
                    $writeValue = $trgKey.SetValue( $oDrvr.Name, $oDrvr.Value, [Microsoft.Win32.RegistryValueKind]::$oType  )  
                    $objObj = new-object psobject -Property @{  
                        Path = $oDrvr.Path  
                        Name = $oDrvr.Name  
                        Value = $trgKey.GetValue( $oDrvr.Name )  
                        Type = $trgKey.GetValueKind( $oDrvr.Name )  
                    }  
                }  
            $objObj  
            }  
        }  
    }  
    # can't ping  
    else { Write-Host "$srcName offline" }  
} 

Using these functions together you can copy all of one computers ODBC connections to another:

$srcConfig = Get-OdbcConfig srcComputerName
Import-OdbcConfig trgComputerName $scrConfig

It's possible to include only your favorite ODBC connection by filtering on the path:

Import-OdbcConfig trgComputerName ( $scrKeys | where { $_.Path -eq "SOFTWARE\ODBC\ODBC.INI\GoodDatabase" } )

Or filtering out ODBC connections you don't like:

Import-OdbcConfig trgComputerName ( $scrKeys | where { $_.Path -ne "SOFTWARE\ODBC\ODBC.INI\DatabaseIHate" } )

Import-OdbcConfig only returns data when setting values or can't ping target, if there's nothing to create it won't say anything.

沉溺在你眼里的海 2024-10-23 02:43:01

如果您在那里找不到注册,根据它们是否是用户 DSN/系统 DSN,它们很可能位于:

[HKEY_USERS\"用户 SID(不要找这个,它会很长)
号)\Software\ODBC\ODBC.INI]

If you can't find the registrations there, depending on if they are User DSN/System DSN, they can very will be in:

[HKEY_USERS\"User SID(dont' look for this, it will be a long
number)\Software\ODBC\ODBC.INI]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文