Hey everyone!
What I am trying to do is have people run this VBS which will pull down their username, computer name, computer SN, and take in a user defined variable (job number). It will then save this information to a file on the C: drive as "Computer Information.txt" with the format "username,computername,computerSN,job#". Then I want it to read in this file to the variable BodyText which I can then place in the body of the email. Every time I do this I get some computer code in the body and not what I want.
Does anyone have a suggestion on making this work, I want those variable to show up in the body, I dont care how we do it.
Thanks!!!!
----BEGIN CODE--------------------------------------
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "localhost")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
Set WshNetwork = WScript.CreateObject("WScript.Network")
on error resume next
Strjnum=InputBox ("What is the Job Number for the site you are at? (xx-xxx)")
Set objWMIService = GetObject(Strjnum)
For each objitem in colitems
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
'---These constants are defined to make the code more readable
Dim fso, info
Set fso = CreateObject("Scripting.FileSystemObject")
Set info = fso.CreateTextFile("C:\Computer Information.txt", 8, True)
info.write WshNetwork.UserName
info.write (",")
info.write WshNetwork.ComputerName
info.write (",")
info.write objitem.serialnumber
info.write (",")
info.write Strjnum
info.Close
next
Dim CI
'---Open the file for reading
Set CI = fs
penTextFile("C:\Computer Information.txt", ForReading)
'---The ReadAll method reads the entire file into the variable BodyText
BodyText= CI.ReadAll
'---Close the file
CI.Close
Set CI = Nothing
Set fso = Nothing
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TEST TEST TEST"
objMessage.From = """PC Inventory Project"" <ithelp@******.com>"
objMessage.To = "dkuhry@******.com"
objMessage.TextBody = BodyText
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...onfiguration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...nfiguration/smtpserver") = "**********.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...ation/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...iguration/sendusername") = "ithelp@******.com"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...iguration/sendpassword") = "w********"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...uration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...nfiguration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c.../smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
wscript.echo "Thank you"
--------END CODE---------------
What I am trying to do is have people run this VBS which will pull down their username, computer name, computer SN, and take in a user defined variable (job number). It will then save this information to a file on the C: drive as "Computer Information.txt" with the format "username,computername,computerSN,job#". Then I want it to read in this file to the variable BodyText which I can then place in the body of the email. Every time I do this I get some computer code in the body and not what I want.
Does anyone have a suggestion on making this work, I want those variable to show up in the body, I dont care how we do it.
Thanks!!!!
----BEGIN CODE--------------------------------------
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "localhost")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
Set WshNetwork = WScript.CreateObject("WScript.Network")
on error resume next
Strjnum=InputBox ("What is the Job Number for the site you are at? (xx-xxx)")
Set objWMIService = GetObject(Strjnum)
For each objitem in colitems
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
'---These constants are defined to make the code more readable
Dim fso, info
Set fso = CreateObject("Scripting.FileSystemObject")
Set info = fso.CreateTextFile("C:\Computer Information.txt", 8, True)
info.write WshNetwork.UserName
info.write (",")
info.write WshNetwork.ComputerName
info.write (",")
info.write objitem.serialnumber
info.write (",")
info.write Strjnum
info.Close
next
Dim CI
'---Open the file for reading
Set CI = fs
'---The ReadAll method reads the entire file into the variable BodyText
BodyText= CI.ReadAll
'---Close the file
CI.Close
Set CI = Nothing
Set fso = Nothing
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TEST TEST TEST"
objMessage.From = """PC Inventory Project"" <ithelp@******.com>"
objMessage.To = "dkuhry@******.com"
objMessage.TextBody = BodyText
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...onfiguration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...nfiguration/smtpserver") = "**********.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...ation/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...iguration/sendusername") = "ithelp@******.com"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...iguration/sendpassword") = "w********"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...uration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c...nfiguration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/c.../smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
wscript.echo "Thank you"
--------END CODE---------------