windows 创建 ODBC 连接的脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1883127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Script to create ODBC connection
提问by Mathew
I need to deploy some software through SMS/SCCM and the software requires that an ODBC connection be created in Windows. The connection information I was given requires a user name and password. I have a batch script to import the connection information into the registry, however I don't know how to go about putting the user name and password in. I'd like to script this or put it in some kind of distributable package.
我需要通过 SMS/SCCM 部署一些软件,并且该软件要求在 Windows 中创建 ODBC 连接。我得到的连接信息需要用户名和密码。我有一个批处理脚本将连接信息导入注册表,但是我不知道如何将用户名和密码放入。我想编写脚本或将其放入某种可分发包中。
Thanks, -Mathew
谢谢,-马修
回答by Izaac Silva
You may use the follow script:
您可以使用以下脚本:
%WINDIR%\System32\odbcconf.exe CONFIGDSN "SQL Server" "DSN=ControltubProducao|Description=ControltubProducao|SERVER=10.23.22.18|Trusted_Connection=No|Database=Controltub"
%WINDIR%\SysWOW64\odbcconf.exe CONFIGDSN "SQL Server" "DSN=ControltubProducao|Description=ControltubProducao|SERVER=10.23.22.18|Trusted_Connection=No|Database=Controltub"
回答by Sylvain Rodrigue
Here's the script I use (jan. 2015). Replace all <> with your names:
这是我使用的脚本(2015 年 1 月)。将所有 <> 替换为您的姓名:
@echo off
cls
echo Configure user Data Sources for <ApplicationName>
echo.
set dsn_name=<OdbcLinkName>
set config_dsn=configdsn "SQL Server" "DSN=%dsn_name%|Server=<SqlServerName>|Database=<DatabaseName>|Trusted_Connection=yes"
%windir%\system32\odbcconf %config_dsn%
%windir%\syswow64\odbcconf %config_dsn%
echo Data Source "%dsn_name%" has been configured.
echo.
echo Done.
echo.
pause
回答by ewall
Here are examples of how to directly edit the ODBC Registry settings with VBScript, PowerShell, or Perl.
以下是如何使用VBScript、PowerShell或Perl直接编辑 ODBC 注册表设置的示例。