Set objNetwork = CreateObject("WScript.Network")
Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
' Email variables:
strServer = "mailhost.abc.com"
strTo = "[email protected]"
strFrom = "[email protected]"
strSubject = "Subject Here"
strBody = "Name: " & objUser.givenName & " " & objUser.sn & VbCrLf & _
"Logon Name: " & objUser.samAccountName & VbCrLf & VbCrLf & "Printers: "
Set objPrinters = objNetwork.EnumPrinterConnections
For intPrinter = 0 To objPrinters.Count - 1 Step 2
strBody = strBody & VbCrLf & objPrinters(intPrinter) & vbTab & objPrinters(intPrinter + 1)
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery("Select Manufacturer,Model From Win32_ComputerSystem")
For Each objComputer In colComputer
strManufacturer = "Manufacturer: " & objComputer.Manufacturer
strModel = "Model: " & objComputer.Model
Next
strBody = strBody & VbCrLf & VbCrLf & "Computer Name: " & objNetwork.ComputerName & VbCrLf & "Computer Model: " & strModel
SendEmail strServer, strTo, strFrom, strSubject, strBody
MsgBox "Email has been sent."
Sub SendEmail(strServer, strTo, strFrom, strSubject, strBody)
Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.To = strTo
objMessage.From = strFrom
objMessage.Subject = strSubject
objMessage.TextBody = strBody
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
Set objMessage = Nothing
End Sub
|