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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie trying something in VBS

Status
Not open for further replies.

klojo80

Technical User
Apr 11, 2015
2
BE
deal all,

on my work we have to get some html pages from clients to register their machines for warranty.
i was browsing google and already got pretty far, having a vbs that did what we needed.

now the only thing is, we need a certain html that is on a linux server, but the internal ipadress is different for every linux machine.
so i would like to put up a window, that asks the cutomer to input his internal IP (ie 192.168.1.whatever) and then it should download the html in question and send it to us by mail.

i got it to work using not the ip but the network name, problem here is that not every linux box has the same name...

i'll post my findings here, hope you can help!


' Set your settings
strFileURL = " strHDLocation = "c:\the_actual_file.htm"

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary

objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start

Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing

objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if

Set objXMLHTTP = Nothing

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "client@mail.com"
objEmail.To = "my@mail.com"
objEmail.Subject = "email subject"
objEmail.Textbody = "some text"
objEmail.AddAttachment "C:\the_actual_file.htm" 'NOTE: DO NOT USE AN "=" SIGN AFTER "AddAttachment"
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = _
"smtp.gmail.com"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send

my script is working, but the only variable is the IP adress wich should be entered by the customer.
another nice thing i would love to add is, that the customer would be able to also add his name into the mail that sends the html file

i hope you people can help out this noob :)
 
Sounds like you just need to use Inputbox. Such as:

Code:
strIP = InputBox("Enter the IP of the server:")

If Len(strIP) > 0 Then
    strFileURL = "[URL unfurl="true"]http://"[/URL] & strIP & "/subfolder1/subfolder2/the_act..."
Else
    MsgBox "You didn't enter an IP"
    'Exit here, or do some other error checking
End If
 
looks like something I needed :)

tnx! going to try this one out!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top