Add Hostname variable in a vbs script
Home › Forums › Scripting › Windows Script Host › Add Hostname variable in a vbs script
This topic contains 2 replies, has 2 voices, and was last updated by vonPryz 9 years, 1 month ago.
-
AuthorPosts
-
November 11, 2010 at 4:28 am #151979
Hi there,
I’ve got the following script:
Set objEmail = CreateObject(“CDO.Message”)
objEmail.From = “[EMAIL=”[email protected]”][email protected][/EMAIL]”
objEmail.To = “[EMAIL=”[email protected]”][email protected][/EMAIL]”
objEmail.Subject = “Server down”
objEmail.Textbody = “Server1 is no longer accessible over the network.”
objEmail.Configuration.Fields.Item _
(“[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]”) = 2
objEmail.Configuration.Fields.Item _
(“[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]”) = _
“smarthost”
objEmail.Configuration.Fields.Item _
(“[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]”) = 25
objEmail.Configuration.Fields.Update
objEmail.Send[/CODE]
I need to put in a variable of the hostname in either the Subject title or in the text body.
I believe strHostName can be used but I don’t know how.Can anyone help?
Tia[CODE]
Set objEmail = CreateObject(“CDO.Message”)
objEmail.From = “[email protected]“
objEmail.To = “[email protected]“
objEmail.Subject = “Server down”
objEmail.Textbody = “Server1 is no longer accessible over the network.”
objEmail.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2
objEmail.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = _
“smarthost”
objEmail.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25
objEmail.Configuration.Fields.Update
objEmail.Send[/CODE]
I need to put in a variable of the hostname in either the Subject title or in the text body.
I believe strHostName can be used but I don’t know how.Can anyone help?
Tia
November 11, 2010 at 9:24 am #347514Re: Add Hostname variable in a vbs script
Use Wscript.Network like so,
Code:Set WshNetwork = WScript.CreateObject(“WScript.Network”)
WScript.Echo WshNetwork.ComputerNameThus, change your script to catenate computer name into the subject string:
Code:Set WshNetwork = WScript.CreateObject(“WScript.Network”)
objEmail.Subject = “Server ” & WshNetwork.ComputerName & ” is down”As usual, thanks go to Guy Thomas.
-vP
-
AuthorPosts
You must be logged in to reply to this topic.