Announcement

Collapse
No announcement yet.

Add Hostname variable in a vbs script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add Hostname variable in a vbs script

    Hi there,

    I've got the following script:

    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/con...tion/sendusing") = 2
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = _
            "smarthost" 
    objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/con...smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
    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
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

  • #2
    Re: Add Hostname variable in a vbs script

    Use Wscript.Network like so,

    Code:
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WScript.Echo WshNetwork.ComputerName
    Thus, 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

    Comment


    • #3
      Re: Add Hostname variable in a vbs script

      Thanks -vP,

      That worked a treat.
      Caesar's cipher - 3

      ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

      SFX JNRS FC U6 MNGR

      Comment

      Working...
      X