Managing Enterprise Systems with the Windows Script Host
Authors: Borge S.
Published year: 2005
Pages: 120-121/242
Buy this book on amazon.com >>

12.12 Using the Process Monitor Event

Problem

You are using Windows NT's Process Monitor program to monitor for problems on a machine. You want to be notified if a monitored threshold is exceeded.

Solution

Process Monitor can have alerts set when a certain threshold is exceeded. A program can be run at this time. To do so, follow these steps:

  1. Start Process Monitor.

  2. Click the View the Alerts icon.

  3. Select the Add to Alert icon to add a new Alert. The Add to Alert dialog box appears, as shown in Figure 12-6.

    click to expand
    Figure 12-6: Add to Alert dialog box

  4. Now set the counter and threshold you want to monitor.

  5. In the Run Program on Alert box, enter the path of the program you want to run. For WSH scripts, you cannot just enter the path of the script (e.g., c:\scripts\script.vbs ). You must execute the script with cscript or wscript (cscript is the logical choice).

Any parameters you want to pass that contain spaces must be surrounded in quotes. For example, the following command line would execute the MailSend script, passing the profile, e-mail address, subject, and mail message:

cscript d:\scripts\MailSend.vbs "Profile" "SMTP:freds@x.com" "Subject" "message"

Note 

You have the option to run the script only once with the First Time option button, and this may be desirable if you only want to be notified of the first instance; otherwise , you might be overwhelmed by messages.

12.13 Attaching Files to a Message

Problem

You need to attach files to a message.

Solution

You can attach files to a message by referencing the Message object's Attachment collection and invoking the Add method:

'sendattach.vbs Const MsgFileData =1 Const MsgFileLink = 2 Const MsgOLE = 3 Dim objSession, objMessage, objRecipient ' Set objSession = CreateObject("MAPI.Session") objSession.Logon "SCB" Set objMessage = objSession.Outbox.Messages.Add("Attachment Test") objMessage.Text= "This is the body of the message" Set objRecipient = _ objMessage.Recipients.Add("Joe Blow ", " SMTP:administrator@acme.com") objRecipient.Resolve Set objAttachment = objMessage.Attachments.Add("Attached File", , _ MsgFileData," c:\data\Weekly.xls") Set objAttachment = objMessage.Attachments.Add("Linked File", , _ MsgFileLink, "\odin\xldata\Weekly.xls") Set objAttachment = objMessage.Attachments.Add("Embedded File", , _ MsgOLE, "c:\data\Weekly.xls") objMessage.Update objMessage.Send objSession.Logoff

Discussion

Messages can also include file attachments. Sending file attachments embeds a specified file in the message, which can then be extracted at the destination. Mail messages can contain one or more file attachments.

Attachments can be included by calling the Add method for the Attachments collection for the current message. The syntax is as follows :

Set objAttachment = objAttachColl.Add([

Name

, Position, Type, Source])

Upon successful execution, it returns a new Attachment object. The Add method can take any of the parameters listed in Table 12-9.

Table 12-9: Attachment Collection Add Method Parameters

NAME

TYPE

DESCRIPTION

Name

String

Descriptive name that appears in the actual message. This is not the file path .

Position

Long

Determines the order in which the attachment will appear in the message.

Type

Long

The type of attachment: MsgFileData , MsgFileLink , MsgOLE , or MsgEmbeddedMessage . The default value is MsgFileData .

Source

String

Specifies the source of the attachment. This varies depending on the attachment type. See the Table 12-10 to determine the source format.

Table 12-10: Message Attachment Types

VALUE

DESCRIPTION

MsgFileData = 1

Specifies that the full contents of a file are included in the message.

MsgFileLink = 2

A file link only sends a pointer to the file. This pointer is the location of the file on disk. This is only practical on internal networks where the recipient(s) has access to the specified disk location. The file link should be specified using the Universal Naming Convention (UNC) format-for example, \Server\Share\FileName.DOC . No file data is actually included in the message-only a reference to the file location.

MsgOLE = 3

Specifies the contents of the document are embedded in the message as an OLE document. The contents of the document appear inside the message, so if an Excel file is included, you actually see the whole spreadsheet or part of the spreadsheet in the message. Specify the full path and file name to a valid OLE document file-for example, C:\DOCUMENT\SALES.XLS .

MsgEmbeddedMessage = 4

Indicates an existing e-mail message is to be included as the attachment. The attachment source is identified using the message ID property of the message you want to attach.

The attachment types listed in Table 12-10 determine how the attachment is included in the message.

The attachment is saved in the message when you call the update or send method on the parent Message object.

See Also

For more information, read the MSDN Library article "Adding Attachments to a Message" ( http://msdn.microsoft.com/library/en-us/cdo/html/_olemsg_adding_attachments_to_a_message.asp ).

Managing Enterprise Systems with the Windows Script Host
Authors: Borge S.
Published year: 2005
Pages: 120-121/242
Buy this book on amazon.com >>