Category Archives: VBScript

How To: List all software installed on a machine with VBScript

This VBScript will list all the software installed on the computername you specify in the first line of code. Simply save the code below in a .vbs file and execute it by running it as:

CSCRIPT.EXE /NOLOGO myscript.vbs >logfile.txt

This will give you a nice text file with all the applications installed on the specified computer.

strComputer = "mycomputername"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")'
Set colSettings = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

WScript.Echo "Installed Software List and OS Information"
WScript.Echo "=========================================="
Wscript.Echo ""

'Computer Information'
Wscript.Echo "COMPUTER INFORMATION"
Wscript.Echo "===================="
Wscript.Echo "Computer Name: " & strComputer
For Each objOperatingSystem in colSettings
'Crop Operating system name for clean name'
Result = InStr(objOperatingSystem.Name, "|")
Result = Result -1
MyString = Left(objOperatingSystem.Name,Result)
'Echo stuff
Wscript.Echo "Operating System: " & MyString
Wscript.Echo "Service Pack: " & objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "Installed In: " & objOperatingSystem.WindowsDirectory
Wscript.Echo ""
Next

'Software Information'
Wscript.Echo "SOFTWARE LIST"
Wscript.Echo "============="
For Each objSoftware in colSoftware
wscript.echo objSoftware.Caption
Next

(18224)

How To: Send email with embedded text file as body with VBScript

This is an easy VBScript that will allow you to send notifications by mail. Thou applications like SQL have the Database mail, if you have log files which you need to send a text log file from an application as a notification.

Just change the basic email information to your likings and the Mail Server configuration. If it’s an open SMTP server leave the MailSendUsername and MailSendPassword empty. To embed a text file in the body, change the Logfile.txt entry to your filename. Save the below code as anything.vbs and run it as a scheduled task.

Dim objEmail
Set objEmail = CreateObject("CDO.Message")

'************************************
'** Seting basic email information **
'************************************
Const EmailFrom = """My server notification"" "
Const EmailTo = "myboss@myserver.com,myself@myserver.com"
Const EmailSubject = "My Notification"

'***************************************
'** Setting Mail Server Configuration **
'***************************************
Const MailSendUsing = "2"
Const MailSendServer = "smtp.myserver.com"
Const MailSendPort = "25"
Const MailSendUsername = "noreply@myserver.com"
Const MailSendPassword = "mypassword"
Const MailSendAuthenticationType = "1"

'**************************************
'** Email Parameters (DO NOT CHANGE) **
'**************************************
objEmail.From = EmailFrom
objEmail.To = EmailTo
objEmail.Subject = EmailSubject
objEmail.Textbody = EmailBody
objEmail.AddAttachment EmailAttachments
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = MailSendUsing
ObjEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailSendServer
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailSendPort
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = MailSendAuthenticationType
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = MailSendUsername
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = MailSendPassword

'*******************************************************
'** Setting a text file to be shown in the email Body **
'*******************************************************
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'** File to be inserted in Body
Const FileToBeUsed = "Logfile.txt"
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'** Open the file for reading
Set f = fso.OpenTextFile(FileToBeUsed, ForReading)
'** The ReadAll method reads the entire file into the variable BodyText
objEmail.Textbody = f.ReadAll
'** Close the file
f.Close
'** Clear variables
Set f = Nothing
Set fso = Nothing

'* cdoSendUsingPickup (1)
'* cdoSendUsingPort (2)
'* cdoSendUsingExchange (3)

'********************************
'** Parameters (DO NOT CHANGE) **
'********************************
ObjEmail.Configuration.Fields.Update
objEmail.Send

(15368)