Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gathering data and formatting an email 1

Status
Not open for further replies.

OregonITFella

IS-IT--Management
Jun 4, 2004
17
0
0
US
VBScript experts, tell me if this can be done. I want to pull the logged on users name and machine name with this code:

Code:
'This will print to the screen what the currently logged on users name is'

Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Username: " & WshNetwork.UserName

'This will give us their machine name

Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Computer Name: " & WshNetwork.ComputerName

and then I want to know if there is in VBScript an ability to send that pulled information into an email? It would be extremely cool if I could also format the email with a To: address already filled out but I don't know if VBScript can do this. The email client is Outlook 2000/2003.

So, the big questions is can it be done?

 
Yes, very easily.

Take a look at this script which I use to notify me if a server reboots. This already grabs the machine name so you just need to add code for the username part and of course modify the message sent.

Code:
'==========================================================================
'
' VBScript Source File -- 
'
' NAME: NotifyReboot.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]	
' DATE  : 02/13/2003
'
' COMMENT: 
'
' This script can be added to a machines startup script in Group Policy to notify
' an e-mail address that the machine has restarted.
'
' You must customize the entries for oDomain, oMyIP and oTo with the proper company information.
' Items to customize are on lines 29, 31 and 33.
'=====================================
 
Dim oName, ODomain, oMyIP, oTo

' Get the computer name
Set WshNetwork = CreateObject("WScript.Network")
oName = WshNetwork.ComputerName

' Set the company specific information

' Company Internet Domain Name
ODomain = "thespidersparlor.com"
' Set the SMTP server IP
oMyIP = "10.0.0.4" 
' Where do you want the message to be delivered
oTo = "markdmac@thespidersparlor.com"


' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing",[/URL] _
cdoSendUsingPort = 2, _
cdoSMTPServer = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver"[/URL]

'// Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'// SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

'// Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With

'// Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oName & "@" & oDomain
.Subject = "Server Reboot"
.TextBody = "Server " & oName & "at company " & ODomain & " was restarted " & now
End With

'// An attachment can be included.
'iMsg.AddAttachment Attachment

'Send the message.
iMsg.Send 

MsgBox "Done"

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I am not sure if this is exactly what I was looking for. Let me clarify what I was hoping to accomplish. I wanted to put a login script for each user that ran and reports their Username, Machine Name and then emails that information to a specified email address. It does not need to report back to the screen for the user. Looking at your example, I am not sure it will do this even if altered as you suggested. Could you expound on this for me? Maybe I missed something in your example. Thanks for your reply though. This in itself is a nifty tool.
 
I spoke too soon. This is EXACTLY what I needed. I did some modifications for my environment, added the username objectys I needed, and VOILA! It works like a charm. You are the man! My eternal gratitude is yours.
 
Glad to be of service. Enjoy.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top