×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

send the HTML file to email

send the HTML file to email

send the HTML file to email

(OP)
hello All,
I have this VBS script to fetch the disk space and it opens as HTML file and please help me to send this via email, please need urgent help




'-----------------------------------------------------------------------------
'Purpose : To perform health check activity - free space on drive
'-----------------------------------------------------------------------------

'**************** Open Text File For Reading ************************

FailedCount=0
SucceededCount=0

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Filelocation = ".\Instances.txt"

If objFSO.FileExists(Filelocation) then
Set objTextFile = objFSO.OpenTextFile(Filelocation, ForReading)
else
MsgBox "File does not exists : " & Filelocation , 16 , "Error"
Set objFSO=nothing
wscript.quit
end if

set WshNetwork = WScript.CreateObject("WScript.Network")
sUsername = WshNetwork.UserName
set WshNetwork = Nothing

'******************* Connecting to each Server in Text File *********************
On Error Resume Next

Do Until objTextFile.AtEndOfStream
If Err.Number <> 0 Then
MsgBox "Error when trying to connect to server <" & strComputer & ">" & vbCRLF & "Error Detail: " & err.description,16,"Error"
Err.Clear
end if

strNextLine = objTextFile.Readline
arrServerList = Split(strNextLine , "vbCrLf")
strComputer = arrServerList(0)
html = html & getJobHistory(strComputer)

Loop
objTextFile.close


TableHeader = "<Table border =""1""><tr><td><b>Servername</b></td><td><b>Drive</b></td><td><b>Total Space(GB)</b></td><td><b>Free Space(GB)</b></td><td><b>" & _
"Used Space(GB)</b></td><td><b>Free %</b></td><td><b>Used %</b></td></B></tr>"

html = TableHeader & html & "</Table><br>"

displayHTML "<font size=6><b>Drive Space Utilization </font></b><br><br>" & html, "Drive Space Utilization"


'**********************************************************************************************************************************************************
'Function
'**********************************************************************************************************************************************************

function getJobHistory(byval ServerName)
set cmd = createobject("ADODB.Command")
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")

cn.open "Provider=SQLOLEDB.1;Data Source=" & ServerName & ";Integrated Security=SSPI"

cmd.activeconnection =cn

cmd.commandtext = "SET NOCOUNT ON DECLARE @hr int DECLARE @fso int DECLARE @drive char(1) DECLARE @odrive int DECLARE @TotalSize varchar(20) DECLARE @FreeSpace varchar(20) DECLARE @MB Numeric " & _
"SET @MB = 1048576 CREATE TABLE #drives (drive char(1) PRIMARY KEY, FreeSpace int NULL, TotalSize int NULL) " & _
" if exists( select 1 from ::fn_servershareddrives()) INSERT #drives(drive) select DriveName from ::fn_servershareddrives() else INSERT #drives(drive,FreeSpace) exec master.dbo.xp_fixeddrives " & _
" EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso " & _
"DECLARE dcur CURSOR LOCAL FAST_FORWARD FOR SELECT drive from #drives ORDER by drive " & _
"OPEN dcur FETCH NEXT FROM dcur INTO @drive WHILE @@FETCH_STATUS=0 " & _
"BEGIN EXEC @hr = sp_OAMethod @fso,'GetDrive', @odrive OUT, @drive IF @hr <> 0 " & _
"EXEC sp_OAGetErrorInfo @fso EXEC @hr = sp_OAGetProperty @odrive,'TotalSize', @TotalSize OUT IF @hr <> 0 " & _
"EXEC sp_OAGetErrorInfo @odrive EXEC @hr = sp_OAGetProperty @odrive,'FreeSpace', @FreeSpace OUT IF @hr <> 0 " & _
"EXEC sp_OAGetErrorInfo @odrive " & _
"UPDATE #drives SET TotalSize=@TotalSize/@MB,FreeSpace=@FreeSpace/@MB WHERE drive=@drive " & _
"FETCH NEXT FROM dcur INTO @drive End Close dcur DEALLOCATE dcur " & _
"EXEC @hr=sp_OADestroy @fso IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso " & _
"SELECT @@servername,drive, TotalSize/1024 as 'Total(GB)', FreeSpace/1024 as 'Free(GB)',(TotalSize/1024)-(FreeSpace/1024) as 'Used(GB)',CAST((FreeSpace/(TotalSize*1.0))*100.0 as int) as 'Free(%)' , 100-CAST((FreeSpace/(TotalSize*1.0))*100.0 as int) as 'Used(%)' FROM #drives ORDER BY drive drop table #drives"
set rs =cmd.execute
'message1="<Table border =""1""><tr><td><b>Servername</b></td><td><b>Drive</b></td><td><b>Total Space(GB)</b></td><td><b>Free Space(GB)</b></td><td><b>" & _
'"Used Space(GB)</b></td><td><b>Free %</b></td><td><b>Used %</b></td></B></tr>"

while rs.eof<>true and rs.bof<>true
FailedFlag = 0

if rs(6) > 85 then
FailedFlag = 1
fontColour="#ff0000"
else
fontColour="#0F00CD"

end if

if FailedFlag = 1 or ShowAll then
message1 = message1 & "<td><font color='" & fontColour & "'>" & rs(0) & "</font></td><td><font color='" & fontColour & "'>" & _
rs(1) & "</font></td><td><font color='" & fontColour & "'>" & rs(2) & "</font></td><td><font color='" & fontColour & "'>" & _
rs(3) & "</font></td><td><font color='" & fontColour & "'>" & rs(4) & "</font></td><td><font color='" & fontColour & "'>" & _
rs(5) & "%</font></td><td><font color='" & fontColour & "'>" & rs(6) &"%</font></td>"

end if

rs.movenext
message1=message1 & "</tr></font>"
wend

getJobHistory = message1
cn.close

end function

sub displayHTML(byval html, Title)

On Error Resume Next

Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "about:blank"

objExplorer.AddressBar = True
objExplorer.MenuBar = True
objExplorer.StatusBar = True
objExplorer.ToolBar = True
objExplorer.Visible = True

objExplorer.Document.Title = Title
objExplorer.Document.Body.InnerHTML = html



end sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close