创建 ODBC 连接的脚本

发布于 2024-08-15 05:18:49 字数 153 浏览 6 评论 0原文

我需要通过 SMS/SCCM 部署一些软件,并且该软件要求在 Windows 中创建 ODBC 连接。我获得的连接信息需要用户名和密码。我有一个批处理脚本将连接信息导入到注册表中,但是我不知道如何将用户名和密码放入其中。我想编写此脚本或将其放入某种可分发包中。

谢谢, -马修

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.

Thanks,
-Mathew

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

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

发布评论

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

评论(4

烟燃烟灭 2024-08-22 05:18:49

您可以使用以下脚本:

%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"

在此处输入图像描述

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"

enter image description here

萝莉病 2024-08-22 05:18:49

以下是如何使用 VBScript PowerShellPerl

Here are examples of how to directly edit the ODBC Registry settings with VBScript, PowerShell, or Perl.

将军与妓 2024-08-22 05:18:49

这是我使用的脚本(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

Here's the script I use (jan. 2015). Replace all <> with your names:

@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
酒与心事 2024-08-22 05:18:49
Option Explicit

Dim strDSNName, strDriver, strServer, strLastUser, strRegional, strDatabase
strDSNName = "DSN NAME"
strDriver = "C:\WINDOWS\system32\SQLSRV32.dll"
strServer = "SERVER ADDRESS"
strLastUser = "USERNAME (PLACEHOLDER)"
strRegional = "Yes"
strDatabase = "DB NAME"

If MsgBox("ODBC configuration listed below is going to be added to current user." & vbcrlf & _
          "Do you want to continue?" & vbcrlf & _
          "DSN Name: " & strDSNName & vbcrlf & _
          "Server: " & strServer & vbcrlf & _
          "Database: " & strDatabase, vbInformation + vbYesNo, "Confirmation Required") = vbYes Then
Else
  MsgBox "Operation cancelled by user.", vbExclamation, "Aborted"
  Wscript.Quit
End If

const HKEY_CURRENT_USER = &H80000001
Dim strComputer, objReg, strKeyPath, strValueName, strValue
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = strDSNName 
strValue = "SQL Server"
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\" & strDSNName
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\" & strDSNName

strValueName = "Database"
strValue = strDatabase
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "Driver"
strValue = strDriver
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "Server"
strValue = strServer
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "Regional"
strValue = strRegional
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "LastUser"
strValue = strLastUser
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

Set objReg = Nothing

If (Err.Number = 0) Then 
  MsgBox "ODBC added successfully!" & vbcrlf & _
         "Details are listed below:" & vbcrlf & _
         "DSN Name: " & strDSNName & vbcrlf & _
         "Server: " & strServer & vbcrlf & _
         "Database: " & strDatabase, vbInformation, "Succeed"
Else
  Wscript.Echo "Operation failed. Error = " & Err.Number
End If
Option Explicit

Dim strDSNName, strDriver, strServer, strLastUser, strRegional, strDatabase
strDSNName = "DSN NAME"
strDriver = "C:\WINDOWS\system32\SQLSRV32.dll"
strServer = "SERVER ADDRESS"
strLastUser = "USERNAME (PLACEHOLDER)"
strRegional = "Yes"
strDatabase = "DB NAME"

If MsgBox("ODBC configuration listed below is going to be added to current user." & vbcrlf & _
          "Do you want to continue?" & vbcrlf & _
          "DSN Name: " & strDSNName & vbcrlf & _
          "Server: " & strServer & vbcrlf & _
          "Database: " & strDatabase, vbInformation + vbYesNo, "Confirmation Required") = vbYes Then
Else
  MsgBox "Operation cancelled by user.", vbExclamation, "Aborted"
  Wscript.Quit
End If

const HKEY_CURRENT_USER = &H80000001
Dim strComputer, objReg, strKeyPath, strValueName, strValue
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = strDSNName 
strValue = "SQL Server"
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\" & strDSNName
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\" & strDSNName

strValueName = "Database"
strValue = strDatabase
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "Driver"
strValue = strDriver
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "Server"
strValue = strServer
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "Regional"
strValue = strRegional
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "LastUser"
strValue = strLastUser
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

Set objReg = Nothing

If (Err.Number = 0) Then 
  MsgBox "ODBC added successfully!" & vbcrlf & _
         "Details are listed below:" & vbcrlf & _
         "DSN Name: " & strDSNName & vbcrlf & _
         "Server: " & strServer & vbcrlf & _
         "Database: " & strDatabase, vbInformation, "Succeed"
Else
  Wscript.Echo "Operation failed. Error = " & Err.Number
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文