Hi guys hope you can help!!
Okay, I have the following code that is just about 100% working, but Id like you nice people to examine it (see if there is anything that really isnt being done as per standard good programming practice etc).
What it does is the following:
Queries the local machine Win32_Process, returns results, pumps the results into a variable within an email message.
So the output is something like the following:
==========================
==========
==========
======= Email Message
List of Running Processes On System: DELL101
Name ProcessID
System Idle Process 0
System 4
etc etc
The problem Im having is the following:
The only way I can the computer name to appear is if I hard code the computer name into my script.
I want to use strComputer = "." but this just returns a dot, not the computer name. So Im not sure where to place it in my script so I dont have to hard code the name.
'=========================
==========
=======TIT
LE OF EMBEDDED HTML (code snippet)
strComputer = "DELL101"
strHTML = strHTML & "<HTML>"
Guys can someone advise me on where Im going wrong in my code so that I dont have to hard code the computer name?
Thanks for any help
==========================
==========
==========
== HERE IS MY CODE:
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strComputer
Const cdoSendUsingPort = 2
Const cdoBasic = 1 'basic (clear-text) authentication
set iMsg = CreateObject("CDO.Message"
)
set iConf = CreateObject("CDO.Configur
ation")
Set Flds = iConf.Fields
With Flds
.Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "smtpServer"
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("
http://schemas.microsoft.com/cdo/configuration/sendusername") = "emailaddress"
.Item("
http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpusessl")
= False
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
) = 60
.Update
End With
'=========================
==========
==========
==========
=========T
ITLE OF EMBEDDED HTML
strComputer = "DELL101"
strHTML = strHTML & "<HTML>"
strHTML = strHTML & "<BODY bgcolor='green'>"
'strComputer = "."
strHTML = strHTML & "List of "
strHTML = "<b>" & "<i>" & strHTML & "Running Processes On System: " & strComputer & "</i>" & "</b>"
strHTML = strHTML & "<p>" & "</p>"
strHTML = strHTML & "<br>" & "<br>"
'=========================
==========
==========
==========
========TA
BLE FOLLOWS
Set objWMIService = GetObject("winmgmts:" & "\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_Process")
strHTML = strHTML & "<table border='1' style='border-collapse: collapse' align='center' bordercolor='purple' bgcolor='pink' width='35%' id='Table1'>"
'=========================
==========
==========
==========
========TA
BLE HEADER ROW
strHTML = strHTML & "<tr bgcolor='#FFFF00'>"
strHTML = strHTML & "<td width='70%'>" & "<b>" & "Name" & "</b>" & "</td>"
strHTML = strHTML & "<td width='30%'>" & "<b>" & "ProcessID" & "</b>" & "</td>" & "</b>"
strHTML = strHTML & "</tr>"
'=========================
==========
==========
==========
==========
======THE ROWS......
For Each objItem in colItems
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='70%'>" & objItem.Name & "</td>"
strHTML = strHTML & "<td width='30%'>" & objItem.ProcessID & "</td>"
strHTML = strHTML & "</tr>"
Next
strHTML = strHTML & "</table>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
'==Apply the settings to the message:
With iMsg
Set .Configuration = iConf
.To = "emailaddress"
.From = """Mr Wiggles"" <emailaddress>"
.Subject = "This is a test CDOSYS message (Sent via Port 25)"
.HTMLBody = strHTML
.Send
End With
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
MsgBox "Mail Sent!"
'=========================
==========
==========
=========C
ODE END