Re: help emailing this script

Tech-Archive recommends: Fix windows errors by optimizing your registry



Do you remember what I wrote in my previous note?

"Remember to pass two arguments to this subroutine
when calling it."

You appear to have ignored my reminder. Your subroutine
"WriteTextFile" requires two parameters, yet you call it with
none!

If this is not clear then have a look at your own subroutine:
sub WriteTextFile(txt, strTextFilePath)
' Procedure to write output to a text file
Dim objFSO,objTextFile
set objFSO = createobject("Scripting.FileSystemObject")
set objTextFile = objFSO.CreateTextFile(strTextFilePath)
objTextFile.Write(txt)
objTextFile.Close
SET objTextFile = nothing
end sub

Now ask yourself these questions:
a) What are the variables "txt" and "strTextFilePath"?
b) Where are they set in the main routine?
c) Where do you use them in the subroutine?


"arthursc" <arthursc@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C88567FB-2011-496A-BF7A-9EB47D1D1F35@xxxxxxxxxxxxxxxx
Sorry as Windows Script Host error message displays;

Script: C:\diskspace.vbs
Line: 8
Char: 1
Error: Wrong number of arguments or invalid property assignment:
'WrtiteTextFile'
Code: 800A01C2
Source: Microsoft VBScirpt runtime error

many thanks
colin.
"Pegasus (MVP)" wrote:

You need to realise that I cannot see your screen. I do not know
which of your lines is "Line 8" and unless you quote the error
message verbatim, I cannot comment on it.


"arthursc" <arthursc@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:523E6D10-B4B5-478E-BAAC-72E6632751CD@xxxxxxxxxxxxxxxx
Hi Pegasus,

Thanks for you imput on htis and most of all your patience. As
mentioned
not
a programmer but wotking on it. Below is the script I have now created
along
with you valuable input. I have two issues now;

script runs but no email sent. When script completes and echo's output
I
get
an erro located at Line 8 Char 1.

here is what I have created;

Option Explicit
const strComputer = "."
const strReport = "c:\diskspace.txt"
Dim objWMIService, objItem, colItems
Dim strDriveType, strDiskSize, txt

GetDiskParms
WriteTextFile
SendFile

Sub GetDiskParms
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_LogicalDisk
WHERE DriveType=3")
txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" &
vbtab
&
"Free(%)" & vbcrlf
DIM pctFreeSpace,strFreeSpace,strusedSpace
For Each objItem in colItems
pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
strDiskSize = Int(objItem.Size /1073741824) & "Gb"
strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) &
"Gb"
txt = txt & objItem.Name & vbtab & strDiskSize & vbtab &
strUsedSpace &
vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf
Next
writeTextFile txt, strReport
wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt
end sub

sub WriteTextFile(txt, strTextFilePath)
' Procedure to write output to a text file
Dim objFSO,objTextFile
set objFSO = createobject("Scripting.FileSystemObject")
set objTextFile = objFSO.CreateTextFile(strTextFilePath)
objTextFile.Write(txt)
objTextFile.Close
SET objTextFile = nothing
end sub



Sub SendFile
schema = "http://schemas.microsoft.com/cdo/configuration/";

Set objEmail = CreateObject("CDO.Message")
With objEmail
.From = "SERVER@xxxxxx"
.To = "me@xxxxxx"
.Subject = "Test Mail"
.Textbody = "The quick brown fox " & Chr(10) & "jumps over the lazy
dog"
.AddAttachment "c:\diskspace.txt"
With .Configuration.Fields
.Item (schema & "sendusing") = 2
.Item (schema & "smtpserver") = "MY MAIL SERVER"
.Item (schema & "smtpserverport") = 25
End With
.Configuration.Fields.Update
.Send
End With
end sub

"Pegasus (MVP)" wrote:






.



Relevant Pages