Category: Scripting

Send email via Gmail SMTP by VBscript (incl. SMTP auth!)
article #341, updated 4844 days ago

Here is a VBscript which, if edited for your Gmail account and environment, will work well on anything XP, Server 2003, or above. It does not require any additional installations, CDO is an object built in to Windows:

EmailSubject = "Sending Email by CDO"
EmailBody = "This is the body of a message sent via" & vbCRLF & _
		"a CDO.Message object using SMTP authentication."

Const EmailFrom = "self@gmail.com"
Const EmailFromName = "My Very Own Name"
Const EmailTo = "someone@destination.com"
Const SMTPServer = "smtp.gmail.com"
Const SMTPLogon = "self@gmail.com"
Const SMTPPassword = "gMaIlPaSsWoRd"
Const SMTPSSL = True
Const SMTPPort = 465

Const cdoSendUsingPickup = 1 	'Send message using local SMTP service pickup directory.
Const cdoSendUsingPort = 2 	'Send the message using SMTP over TCP/IP networking.

Const cdoAnonymous = 0 	' No authentication
Const cdoBasic = 1 	' BASIC clear text authentication
Const cdoNTLM = 2 	' NTLM, Microsoft proprietary authentication

' First, create the message

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = EmailSubject
objMessage.From = """" & EmailFromName & """ <" & EmailFrom & ">"
objMessage.To = EmailTo
objMessage.TextBody = EmailBody

' Second, configure the server

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPLogon

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPPassword

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = SMTPSSL

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

' Now send the message!

objMessage.Send

Categories:      

==============

Detect Windows versions in batch files
article #301, updated 4941 days ago

Here is some excellent code:

http://adamstech.wordpress.com/2009/07/16/use-a-batch-file-to-detect-windows-2k-xp-2003-vista-or-7/

Categories:      

==============

A simple backup system with disk2vhd
article #265, updated 5033 days ago

This works, to back up C drive to \\DEST_SERVER\E$\SHARE, if disk2vhd.exe is within the path:

REM
REM A simple backup system using disk2vhd
REM
REM version 1.3, by J.E.B., 2011-02-22
REM
REM requires 'disk2vhd.exe' to be in the path
REM

setLocal EnableDelayedExpansion

REM "DRIVES" can be one drive identifier with colon, multiple separated by spaces,
REM or asterisk for all.  
REM "DEST" can be a drive letter or a UNC.

SET DRIVES="*"
SET DEST="\\SERVER\SHARE"

REM Keep most recent 4 VHD files in DEST, delete the rest

for /f "skip=4 tokens=* delims= " %%a in ('dir/b/o-d %DEST%\*.VHD') do (
del %DEST%\%%a
)

REM Backup to VHD

C:
cd \
DISK2VHD %DRIVES% %DEST%\D2VBK--%date:~-10,2%%date:~-7,2%%date:~-4,4%_TS.VHD

Categories:      

==============

Delete Windows share by script
article #172, updated 5261 days ago

Put the below in a VBS file and run it (from a batch file perhaps) with ‘wscript filename.vbs’.

' The name of the share.
strShareName = "SHARE"

' SERVERNAME has to be the hostname of the machine containing the sahre
Set objfServer = GetObject("WinNT://SERVERNAME/lanmanserver")
objfServer.Delete "Fileshare", strShareName
Set objfServer= Nothing

Categories:      

==============

Hidden Start – Run Console Applications & Batch Files without any Window in the Background
article #165, updated 5277 days ago

A great tool:

http://www.ntwind.com/software/utilities/hstart.html

Categories:      

==============

Example FTP batch (.CMD) script
article #153, updated 5332 days ago

A very good example is on this page:

http://ss64.com/nt/ftp.html

Categories:      

==============

A msgbox in a batch file
article #149, updated 5341 days ago

This works in .CMD files!  A nice little message box.

msg * Hello!!!!!!!!!!

Categories:      

==============

XPSP3 and Adobe Reader 9
article #139, updated 5370 days ago

Just learned this:  in scripted Web applications, there are sometimes incompatibilities between XPSP3 and Adobe Reader 9.  Sometimes both SP3 and Reader 9 have had to be rolled back to previous versions, sometimes just one of the two.

Categories: