WSH: Crear una entrada ODBC para SQL Server
Posted on November 5th, 2007 in Código, Script |
Este script automatiza la creación de una entra ODBC para conectarse a un servidor SQL Server.
CreateDSN.vbs
Visual Basic:
-
'===================
-
'
-
' File: CreateDSN.vbs
-
'
-
' AUTHOR: Dixan Martinez
-
' Date : 2/2/2000
-
'
-
' COMMENT:
-
'
-
'===================
-
-
-
-
Dim DataSourceName
-
Dim DatabaseName
-
Dim Description
-
Dim DriverPath
-
Dim DriverName
-
Dim LastUser
-
Dim Regional
-
Dim Server
-
-
Const SystemFolder= 1
-
Dim fso
-
Dim SysFolder
-
Dim SysFolderPath
-
-
Set fso = wscript.CreateObject("Scripting.FileSystemObject")
-
Set SysFolder =fso.GetSpecialFolder(SystemFolder)
-
SysFolderPath= SysFolder.Path
-
-
Set oArg= wscript.Arguments
-
-
if oArg.Count <> 4 then
-
call Usage
-
end if
-
-
'Specify the DSN parameters.
-
-
DataSourceName = oArg(0)
-
DatabaseName = oArg(1)
-
Description = "Odbc de BD" & DatabaseName
-
DriverPath = SysFolderPath & "\sqlsrv32.dll"
-
Server = oArg(2)
-
LastUser = oArg(3)
-
-
DriverName = "SQL Server"
-
-
'Creamos objetos que escriben en el registro
-
Set WshShell = WScript.CreateObject("WScript.Shell")
-
-
'Establecemos el Key del DSn en el registro
-
Dim RegEdPath
-
RegEdPath= "HKLM\SOFTWARE\ODBC\ODBC.INI\" & DataSourceName & "\"
-
'Grabamos
-
WshShell.RegWrite RegEdPath , ""
-
-
'Ponemos los valores de la nueva Key correspondiente al DSN
-
-
WshShell.RegWrite RegEdPath & "Database" , DatabaseName
-
WshShell.RegWrite RegEdPath & "Description" , Description
-
WshShell.RegWrite RegEdPath & "Driver" , DriverPath
-
WshShell.RegWrite RegEdPath & "LastUser" , LastUser
-
WshShell.RegWrite RegEdPath & "Server" , Server
-
-
'Escribo en el Key "ODBC Data Sources" para poder listar el nuevo DSN
-
' en el ODBC Manager
-
-
WshShell.RegWrite "HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\" & DataSourceName , DriverName
-
-
-
-
wscript.Quit
-
-
'--------------------
-
Sub Usage
-
wscript.echo "Create a DSN to access a SQL Server database with ODBC"
-
wscript.echo "Uso :"
-
wscript.echo "CreateDSN.vbs <DSNName> <DataBaseName> <SQLServer> <User> "
-
wscript.echo ""
-
wscript.echo "Ejemplo 1 : CreaDSN.vbs NuevoDSN Pub MySQLServer AdminUser"
-
wscript.Quit
-
end sub
Popularidad: 64%

