paulwhelan
asked on
check if a website is 'live'
Hi
Is it possible to do this in VB?
I need to create a 'Job' that I can run with SQL Server and I think I might need to do that with a VB script.
Thanks
https://www.experts-exchange.com/questions/21871178/Auto-insert-and-check-if-website-is-live.html
I know that I can check if a website is 'live' by doing this in C#
HttpWebRequest webRequest = (HttpWebRequest)WebRequest .Create(we bsiteToReq uest);
webRequest.Timeout = 6000;
HttpWebResponse webResponse = (HttpWebResponse)webReques t.GetRespo nse();
string responseStream = webResponse.GetResponseHea der("Conte nt-Length" );
But does anyone know how to set up a scheduled task to check if a site is 'live'
and then insert into a table in my sql server database to say if its live or not?
Is it possible to do this in VB?
I need to create a 'Job' that I can run with SQL Server and I think I might need to do that with a VB script.
Thanks
https://www.experts-exchange.com/questions/21871178/Auto-insert-and-check-if-website-is-live.html
I know that I can check if a website is 'live' by doing this in C#
HttpWebRequest webRequest = (HttpWebRequest)WebRequest
webRequest.Timeout = 6000;
HttpWebResponse webResponse = (HttpWebResponse)webReques
string responseStream = webResponse.GetResponseHea
But does anyone know how to set up a scheduled task to check if a site is 'live'
and then insert into a table in my sql server database to say if its live or not?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There's always URLDownloadToFile...
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Function IsOnline() As Boolean
IsOnline = DownloadFile("http://yoursite.com", App.Path & "\check.html")
End Sub
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Function IsOnline() As Boolean
IsOnline = DownloadFile("http://yoursite.com", App.Path & "\check.html")
End Sub
...or you could 'PING' the site domain...
"IcmpSendEcho: Ping a Machine by IP Address"
[ http://vbnet.mvps.org/index.html?code/internet/ping.htm]
BFN,
fp.
"IcmpSendEcho: Ping a Machine by IP Address"
[ http://vbnet.mvps.org/index.html?code/internet/ping.htm]
BFN,
fp.
ASKER
Thanks Guys,
In Enterprise Manager it says
Select Job Commend Type
I select Active Script (for example VBScript or Javascript)
Then it says type the VBScript.
Do I just type
Function WebFileExists(ByVal vWebAddress)
Dim oXMLHTTP, vWebText
Set oXMLHTTP = CreateObject("msxml2.xmlht tp")
oXMLHTTP.Open "GET", vWebAddress, False
oXMLHTTP.send
WebFileExists = False
If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = True
Set oXMLHTTP = Nothing
Set vWebText = Nothing
End Function
in there?
Also can I call the function in there?
If so where?
Do I just do
WebFileExists("https://www.experts-exchange.com")
And finally how do I update the table with this Job?
Thanks
Paul
In Enterprise Manager it says
Select Job Commend Type
I select Active Script (for example VBScript or Javascript)
Then it says type the VBScript.
Do I just type
Function WebFileExists(ByVal vWebAddress)
Dim oXMLHTTP, vWebText
Set oXMLHTTP = CreateObject("msxml2.xmlht
oXMLHTTP.Open "GET", vWebAddress, False
oXMLHTTP.send
WebFileExists = False
If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = True
Set oXMLHTTP = Nothing
Set vWebText = Nothing
End Function
in there?
Also can I call the function in there?
If so where?
Do I just do
WebFileExists("https://www.experts-exchange.com")
And finally how do I update the table with this Job?
Thanks
Paul
ASKER
For example I enter this
Function WebFileExists(ByVal vWebAddress)
Dim oXMLHTTP, vWebText
Set oXMLHTTP = CreateObject("msxml2.xmlht tp")
oXMLHTTP.Open "GET", vWebAddress, False
oXMLHTTP.send
WebFileExists = False
If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = True
Set oXMLHTTP = Nothing
Set vWebText = Nothing
End Function
WebFileExists("www.yahoo.com");
and when I try to parse it says
'Expected end of statement"
thanks
PAul
Function WebFileExists(ByVal vWebAddress)
Dim oXMLHTTP, vWebText
Set oXMLHTTP = CreateObject("msxml2.xmlht
oXMLHTTP.Open "GET", vWebAddress, False
oXMLHTTP.send
WebFileExists = False
If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = True
Set oXMLHTTP = Nothing
Set vWebText = Nothing
End Function
WebFileExists("www.yahoo.com");
and when I try to parse it says
'Expected end of statement"
thanks
PAul
ASKER
Ok back to basics
I added a Job in Enterprise manager and this is the script
set FSO = server.createobject("Scrip ting.FileS ystemObjec t")
set filewriter = FSO.createtextfile("d:/you rdirectory /yourfile. html")
filewriter.writeline "hello world"
set fso = nothing
set filewriter = nothing
And I set it to run every minute.
However
1 - nothing was created on my harddisk
2 - i cant seem to go back to edit or view the job?
thanks
I added a Job in Enterprise manager and this is the script
set FSO = server.createobject("Scrip
set filewriter = FSO.createtextfile("d:/you
filewriter.writeline "hello world"
set fso = nothing
set filewriter = nothing
And I set it to run every minute.
However
1 - nothing was created on my harddisk
2 - i cant seem to go back to edit or view the job?
thanks
Take your VBScript you pasted above & place it in a distinct file external to Enterprise Manager (and give it a ".vbs" extension).
Now set Enterprise Manager to run this .vbs file instead ("Execute Process Task" -> Set "Win32 Process" to be the full folder path/filename where you have saved the .vbs file).
Once you have this working we can look at re-coding the above suggestions in VBScript, rather than in VB(A) as they are shown in the previous comments.
BFN,
fp.
Now set Enterprise Manager to run this .vbs file instead ("Execute Process Task" -> Set "Win32 Process" to be the full folder path/filename where you have saved the .vbs file).
Once you have this working we can look at re-coding the above suggestions in VBScript, rather than in VB(A) as they are shown in the previous comments.
BFN,
fp.
Hi Paul,
Putting just:
WebFileExists("https://www.experts-exchange.com")
Won't do anything, since vbs needs to know what to do with that return value. You could assign it to a variable, or even just msgbox it for testing. Also, you may run into errors if you don't include the http:// beforehand. Try pasting the following into your .vbs file like fp suggested or into the enterprise manager:
msgbox WebFileExists("https://www.experts-exchange.com")
Function WebFileExists(ByVal vWebAddress)
Dim oXMLHTTP, vWebText
Set oXMLHTTP = CreateObject("msxml2.xmlht tp")
oXMLHTTP.Open "GET", vWebAddress, False
oXMLHTTP.send
vwebfileexists = False
If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = True
Set oXMLHTTP = Nothing
Set vWebText = Nothing
End Function
If you put it into a .vbs file, double click that .vbs file to run it after saving without scheduling it as a task.
Matt
Putting just:
WebFileExists("https://www.experts-exchange.com")
Won't do anything, since vbs needs to know what to do with that return value. You could assign it to a variable, or even just msgbox it for testing. Also, you may run into errors if you don't include the http:// beforehand. Try pasting the following into your .vbs file like fp suggested or into the enterprise manager:
msgbox WebFileExists("https://www.experts-exchange.com")
Function WebFileExists(ByVal vWebAddress)
Dim oXMLHTTP, vWebText
Set oXMLHTTP = CreateObject("msxml2.xmlht
oXMLHTTP.Open "GET", vWebAddress, False
oXMLHTTP.send
vwebfileexists = False
If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = True
Set oXMLHTTP = Nothing
Set vWebText = Nothing
End Function
If you put it into a .vbs file, double click that .vbs file to run it after saving without scheduling it as a task.
Matt
It would be better to use MsgBox CStr(WebFileExists("https://www.experts-exchange.com")), as this converts the boolean value to a string containing "True" or "False". I know this is true of "proper" VB.
Other than that, mvidas has the right idea.
Other than that, mvidas has the right idea.
I think Matt was simply demonstrating the result, or how the function may be used , but yes, the MsgBox statement does expect a string data type as the parameter relating to the text message to display. If any other data type is used, then the VBA interpreter will convert to a string prior to presentation. This is also the case within Visual Basic (for Windows).
FYI: Further issues have been raised in another question:
"Adding a VB 'Job' in SQL Enterprise Manager"
[ https://www.experts-exchange.com/questions/21872209/Adding-a-VB-'Job'-in-SQL-Enterprise-Manager.html ]
BFN,
fp.
FYI: Further issues have been raised in another question:
"Adding a VB 'Job' in SQL Enterprise Manager"
[ https://www.experts-exchange.com/questions/21872209/Adding-a-VB-'Job'-in-SQL-Enterprise-Manager.html ]
BFN,
fp.
ASKER
Hi guys
Sorry for delayed reply.
Where exactly is
"Execute Process Task"
for the command
"Execute Process Task" -> Set "Win32 Process"
I cant seem to find it in Enterprise Manager.
Thanks
Paul
Sorry for delayed reply.
Where exactly is
"Execute Process Task"
for the command
"Execute Process Task" -> Set "Win32 Process"
I cant seem to find it in Enterprise Manager.
Thanks
Paul
ASKER
Anyone?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Paul?
Thanks Dan. No objections from me.
' vwebfileexists = False
WebFileExists = False
Sorry about that! Matt