?
Solved

check if a website is 'live'

Posted on 2006-06-01
20
Medium Priority
?
491 Views
Last Modified: 2012-05-05
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


http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21871178.html

I know that I can check if a website is 'live' by doing this in C#

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(websiteToRequest);
            webRequest.Timeout = 6000;
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
string responseStream = webResponse.GetResponseHeader("Content-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?

0
Comment
Question by:paulwhelan
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 120 total points
ID: 16808696
Hi Paul,

Take a look at my WebFileExists function from http:Q_21870964.html#16806984 
Should be exactly what you're looking for.  If you're going to be doing this in VBScript instead of just vb, use:

Function WebFileExists(ByVal vWebAddress)
 Dim oXMLHTTP, vWebText
 Set oXMLHTTP = CreateObject("msxml2.xmlhttp")
 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

Matt
0
 
LVL 35

Expert Comment

by:mvidas
ID: 16808703
Oops.. looks like my fingers got ahead of my, I put a 'v' in there:

' vwebfileexists = False
 WebFileExists = False

Sorry about that! Matt
0
 
LVL 5

Expert Comment

by:burningmace
ID: 16810008
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16813190
...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.
0
 

Author Comment

by:paulwhelan
ID: 16814607
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.xmlhttp")
 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("www.experts-exchange.com")

And finally how do I update the table with this Job?
Thanks
Paul



0
 

Author Comment

by:paulwhelan
ID: 16814620
For example I enter this

Function WebFileExists(ByVal vWebAddress)
 Dim oXMLHTTP, vWebText
 Set oXMLHTTP = CreateObject("msxml2.xmlhttp")
 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
0
 

Author Comment

by:paulwhelan
ID: 16815017
Ok back to basics

I added a Job in Enterprise manager and this is the script

set FSO = server.createobject("Scripting.FileSystemObject")
set filewriter = FSO.createtextfile("d:/yourdirectory/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
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16815158
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.
0
 
LVL 35

Expert Comment

by:mvidas
ID: 16816647
Hi Paul,

Putting just:
 WebFileExists("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("http://www.experts-exchange.com")

Function WebFileExists(ByVal vWebAddress)
 Dim oXMLHTTP, vWebText
 Set oXMLHTTP = CreateObject("msxml2.xmlhttp")
 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
0
 
LVL 5

Expert Comment

by:burningmace
ID: 16818922
It would be better to use MsgBox CStr(WebFileExists("http://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.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16824977
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"
[ http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21872209.html ]

BFN,

fp.
0
 

Author Comment

by:paulwhelan
ID: 16884434
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

0
 

Author Comment

by:paulwhelan
ID: 16932673
Anyone?
0
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 120 total points
ID: 16958482
These steps applicable to Microsoft SQL Enterprise Manager 8.0.

Run "SQL Server Enterprise Manager".

Select the appropriate server.

Expand the treeview beneath the server to show the "Data Transformation Services" branch.

Right-click the branch & choose "New Package" from the pop-up menu.

When the "DTS Package: <New Package>" window is shown you will see a toolbar with the following:

Package
Edit
Connection
Task
Workflow
(and then a set of icons)

Click "Task", then "4/ Execute Process Task".

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 17295363
Paul?
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 17322176
Thanks Dan.  No objections from me.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question