|
Prev: VB scripting help
Next: Win XP SP3 database access
From: arthursc on 15 Jun 2008 16:57 Hi I have the following script that I want to email the output in html to some users. I am not a vbscripting guy, so would not know where to start. Your help is appreciated. Option Explicit const strComputer = "." const strReport = "c:\diskspace.txt" Dim objWMIService, objItem, colItems Dim strDriveType, strDiskSize, txt 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 For Each objItem in colItems DIM pctFreeSpace,strFreeSpace,strusedSpace 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 ' Procedure to write output to a text file private sub writeTextFile(byval txt,byval strTextFilePath) Dim objFSO,objTextFile set objFSO = createobject("Scripting.FileSystemObject") set objTextFile = objFSO.CreateTextFile(strTextFilePath) objTextFile.Write(txt) objTextFile.Close SET objTextFile = nothing end sub
From: ThatsIT.net.au on 16 Jun 2008 07:16 Here is an example I made for someone else, http://dev.thatsit.net.au/samples/wsh/thatsit/messaging/sendemailwithdelveryreceipt.aspx remove this line if you don't want a read receipt ..DSNOptions = CDO_SUCCESS_FAIL_DELAY "arthursc" <arthursc(a)discussions.microsoft.com> wrote in message news:D4D0A5F8-766F-4CF1-AE68-421D838E4245(a)microsoft.com... > Hi > > I have the following script that I want to email the output in html to > some > users. > > I am not a vbscripting guy, so would not know where to start. > > Your help is appreciated. > > Option Explicit > > const strComputer = "." > const strReport = "c:\diskspace.txt" > > > Dim objWMIService, objItem, colItems > Dim strDriveType, strDiskSize, txt > > 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 > For Each objItem in colItems > > DIM pctFreeSpace,strFreeSpace,strusedSpace > > 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 > > ' Procedure to write output to a text file > private sub writeTextFile(byval txt,byval strTextFilePath) > Dim objFSO,objTextFile > > set objFSO = createobject("Scripting.FileSystemObject") > > set objTextFile = objFSO.CreateTextFile(strTextFilePath) > > objTextFile.Write(txt) > > objTextFile.Close > SET objTextFile = nothing > end sub
From: arthursc on 16 Jun 2008 07:33 Thanks...But, How do I add this to my script below and attatch the output? "ThatsIT.net.au" wrote: > Here is an example I made for someone else, > http://dev.thatsit.net.au/samples/wsh/thatsit/messaging/sendemailwithdelveryreceipt.aspx > > remove this line if you don't want a read receipt > .DSNOptions = CDO_SUCCESS_FAIL_DELAY > > > "arthursc" <arthursc(a)discussions.microsoft.com> wrote in message > news:D4D0A5F8-766F-4CF1-AE68-421D838E4245(a)microsoft.com... > > Hi > > > > I have the following script that I want to email the output in html to > > some > > users. > > > > I am not a vbscripting guy, so would not know where to start. > > > > Your help is appreciated. > > > > Option Explicit > > > > const strComputer = "." > > const strReport = "c:\diskspace.txt" > > > > > > Dim objWMIService, objItem, colItems > > Dim strDriveType, strDiskSize, txt > > > > 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 > > For Each objItem in colItems > > > > DIM pctFreeSpace,strFreeSpace,strusedSpace > > > > 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 > > > > ' Procedure to write output to a text file > > private sub writeTextFile(byval txt,byval strTextFilePath) > > Dim objFSO,objTextFile > > > > set objFSO = createobject("Scripting.FileSystemObject") > > > > set objTextFile = objFSO.CreateTextFile(strTextFilePath) > > > > objTextFile.Write(txt) > > > > objTextFile.Close > > SET objTextFile = nothing > > end sub >
From: Pegasus (MVP) on 16 Jun 2008 09:11 You could use this code to generate an EMail note and optionally add an attachment: schema = "http://schemas.microsoft.com/cdo/configuration/" Set objEmail = CreateObject("CDO.Message") With objEmail .From = "arthur(a)arthur.com" .To = "andrew(a)andrew.com" .Subject = "Test Mail" .Textbody = "The quick brown fox " & Chr(10) & "jumps over the lazy dog" .AddAttachment "d:\Testfile.txt" With .Configuration.Fields .Item (schema & "sendusing") = 2 .Item (schema & "smtpserver") = "mail.arthur.com" .Item (schema & "smtpserverport") = 25 .Item (schema & "smtpauthenticate") = cdoBasic .Item (schema & "sendusername") = "arthur(a)arthur.com" .Item (schema & "sendpassword") = "somepassword" End With .Configuration.Fields.Update .Send End With "arthursc" <arthursc(a)discussions.microsoft.com> wrote in message news:FEECF420-1D45-47FA-8473-D91BBE933C9B(a)microsoft.com... > Thanks...But, > > How do I add this to my script below and attatch the output? > > "ThatsIT.net.au" wrote: > >> Here is an example I made for someone else, >> http://dev.thatsit.net.au/samples/wsh/thatsit/messaging/sendemailwithdelveryreceipt.aspx >> >> remove this line if you don't want a read receipt >> .DSNOptions = CDO_SUCCESS_FAIL_DELAY >> >> >> "arthursc" <arthursc(a)discussions.microsoft.com> wrote in message >> news:D4D0A5F8-766F-4CF1-AE68-421D838E4245(a)microsoft.com... >> > Hi >> > >> > I have the following script that I want to email the output in html to >> > some >> > users. >> > >> > I am not a vbscripting guy, so would not know where to start. >> > >> > Your help is appreciated. >> > >> > Option Explicit >> > >> > const strComputer = "." >> > const strReport = "c:\diskspace.txt" >> > >> > >> > Dim objWMIService, objItem, colItems >> > Dim strDriveType, strDiskSize, txt >> > >> > 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 >> > For Each objItem in colItems >> > >> > DIM pctFreeSpace,strFreeSpace,strusedSpace >> > >> > 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 >> > >> > ' Procedure to write output to a text file >> > private sub writeTextFile(byval txt,byval strTextFilePath) >> > Dim objFSO,objTextFile >> > >> > set objFSO = createobject("Scripting.FileSystemObject") >> > >> > set objTextFile = objFSO.CreateTextFile(strTextFilePath) >> > >> > objTextFile.Write(txt) >> > >> > objTextFile.Close >> > SET objTextFile = nothing >> > end sub >>
From: arthursc on 16 Jun 2008 09:41
Thanks pegasus, Where do I add this in my script? "Pegasus (MVP)" wrote: > You could use this code to generate an EMail note and > optionally add an attachment: > schema = "http://schemas.microsoft.com/cdo/configuration/" > > Set objEmail = CreateObject("CDO.Message") > With objEmail > .From = "arthur(a)arthur.com" > .To = "andrew(a)andrew.com" > .Subject = "Test Mail" > .Textbody = "The quick brown fox " & Chr(10) & "jumps over the lazy dog" > .AddAttachment "d:\Testfile.txt" > With .Configuration.Fields > .Item (schema & "sendusing") = 2 > .Item (schema & "smtpserver") = "mail.arthur.com" > .Item (schema & "smtpserverport") = 25 > .Item (schema & "smtpauthenticate") = cdoBasic > .Item (schema & "sendusername") = "arthur(a)arthur.com" > .Item (schema & "sendpassword") = "somepassword" > End With > .Configuration.Fields.Update > .Send > End With > > > "arthursc" <arthursc(a)discussions.microsoft.com> wrote in message > news:FEECF420-1D45-47FA-8473-D91BBE933C9B(a)microsoft.com... > > Thanks...But, > > > > How do I add this to my script below and attatch the output? > > > > "ThatsIT.net.au" wrote: > > > >> Here is an example I made for someone else, > >> http://dev.thatsit.net.au/samples/wsh/thatsit/messaging/sendemailwithdelveryreceipt.aspx > >> > >> remove this line if you don't want a read receipt > >> .DSNOptions = CDO_SUCCESS_FAIL_DELAY > >> > >> > >> "arthursc" <arthursc(a)discussions.microsoft.com> wrote in message > >> news:D4D0A5F8-766F-4CF1-AE68-421D838E4245(a)microsoft.com... > >> > Hi > >> > > >> > I have the following script that I want to email the output in html to > >> > some > >> > users. > >> > > >> > I am not a vbscripting guy, so would not know where to start. > >> > > >> > Your help is appreciated. > >> > > >> > Option Explicit > >> > > >> > const strComputer = "." > >> > const strReport = "c:\diskspace.txt" > >> > > >> > > >> > Dim objWMIService, objItem, colItems > >> > Dim strDriveType, strDiskSize, txt > >> > > >> > 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 > >> > For Each objItem in colItems > >> > > >> > DIM pctFreeSpace,strFreeSpace,strusedSpace > >> > > >> > 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 > >> > > >> > ' Procedure to write output to a text file > >> > private sub writeTextFile(byval txt,byval strTextFilePath) > >> > Dim objFSO,objTextFile > >> > > >> > set objFSO = createobject("Scripting.FileSystemObject") > >> > > >> > set objTextFile = objFSO.CreateTextFile(strTextFilePath) > >> > > >> > objTextFile.Write(txt) > >> > > >> > objTextFile.Close > >> > SET objTextFile = nothing > >> > end sub > >> > > > |