Agregar una referencia a Microsoft Scripting Runtime
Ejemplo:
Dim dict As New Dictionary
dict.Add "abc", "prueba 1"
dict.Add "xxx", "prueba 2"
MsgBox (dict("abc"))
http://www.kamath.com/tutorials/tut009_dictionary.asp
Mostrando entradas con la etiqueta vbscript. Mostrar todas las entradas
Mostrando entradas con la etiqueta vbscript. Mostrar todas las entradas
Enviar mails desde vbscript con CDO
EnviarMail """Nombre destinatario"" ", "destinatario@abc.com", "prueba", "esta es una prueba de mail"
Sub EnviarMail(Origen, destinatario, Subject, body)
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = Subject
objMessage.From = Origen
objMessage.To = destinatario
objMessage.TextBody = body
objMessage.AddAttachment "c:\temp\11.txt"
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "servidor.correo.net"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "userid@X.net"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
End Sub
Conectarse a SQLServer desde vbscript
Una forma sencilla de crear el string de conexión es utilizando este tip: http://expressraider.blogspot.com/2009/12/crear-conexion-dsnless.html
Set conn = CreateObject("ADODB.Connection")
wscript.timeout = 0
conn.open "Provider=SQLNCLI.1;Persist Security Info=False;User ID=usr1;Password=pwd1;Initial Catalog=nombreBase;Data Source=nombreServidor\nombreInstancia"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = conn
objCommand.CommandTimeout = 120000
objCommand.CommandText = "SELECT * FROM tabla"
Set rs = CreateObject("ADODB.recordset")
Set rs = objCommand.Execute()
Crear conexión DSNLess
This may not be as big of a deal for many of you that are strictly using the Reporting features of SMS 2003 but if you are looking to do more advanced reporting from external data sources you might want to create a DSNless connection. Normally you'll need to either create a DSN on a web server to get a SQL connection working or modify your global.asa file. I don't do either of these. Here's what to do (this example will assume you want to build a connection string to a SQL server):
1. Create a file called "connect.udl" on your desktop or wherever.
2. Right-Click it and select "Properties".
3. On the 'Provider' tab select "Microsoft OLE DB Provider for SQL Server"
4. Go to the 'Connection' tab and fill out the Server name, user name and password which you wish to create the connection with (service accounts only please and local SQL accounts are better to use for security purposes) and the database to access. Click the check box for "Allow saving password". I'm using the SA account for the purposes of this demonstration but I suggest that you do not!
5. Click 'Test Connection' and you should see a "Test Connection Succeeded" message if all the server and credential information has been filled out successfully.
6. Click 'OK' to save the information.
7. Open the connect.udl file with notepad and you should see the following text:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Password=SAPassword;Persist Security Info=True;User ID=SA;Initial Catalog=Master;Data Source=SQLSERVER
Now you have built a successful connection string to use in an ASP page or VBScript to connect to a SQL server with. An example of connecting to an SMS database and grabbing all the records in the System_DATA table could be (in VBScript):
This example might help more for most when creating external ASP pages than VBScripts, but you get the idea.
Fuente: http://www.myitforum.com/articles/19/view.asp?id=8600
1. Create a file called "connect.udl" on your desktop or wherever.
2. Right-Click it and select "Properties".
3. On the 'Provider' tab select "Microsoft OLE DB Provider for SQL Server"
4. Go to the 'Connection' tab and fill out the Server name, user name and password which you wish to create the connection with (service accounts only please and local SQL accounts are better to use for security purposes) and the database to access. Click the check box for "Allow saving password". I'm using the SA account for the purposes of this demonstration but I suggest that you do not!
5. Click 'Test Connection' and you should see a "Test Connection Succeeded" message if all the server and credential information has been filled out successfully.
6. Click 'OK' to save the information.
7. Open the connect.udl file with notepad and you should see the following text:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Password=SAPassword;Persist Security Info=True;User ID=SA;Initial Catalog=Master;Data Source=SQLSERVER
Now you have built a successful connection string to use in an ASP page or VBScript to connect to a SQL server with. An example of connecting to an SMS database and grabbing all the records in the System_DATA table could be (in VBScript):
ConnStr = "SQLOLEDB.1;Password=SAPassword;Persist Security Info=True;User ID=SA;Initial Catalog=Master;Data Source=SQLSERVER"
SQL = "Select * From System_DATA"
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open Connstr
objRS.CursorLocation = 3
objRS.Open SQL, objConn, 1, 1
This example might help more for most when creating external ASP pages than VBScripts, but you get the idea.
Fuente: http://www.myitforum.com/articles/19/view.asp?id=8600
Suscribirse a:
Entradas (Atom)