Call an ASP file from an vb EXE

Posted on 2004-10-22
Last Modified: 2010-05-02
I want to make an .EXE file that I can shadule to run daily.
When this file gets executed I want it to run/call an .ASP page.
How can I do this?
Question by:AutomaticSlim
    LVL 32

    Expert Comment

    Add a reference to "Microsoft Internet Controls" from the Project->References menu.
    Place a Webbrowser control on your form.

    Sub Form_Load()

    Webbrowser1.Navigate2 ""

    end Sub
    LVL 48

    Expert Comment

    by:Ryan Chong
    try use URLDownloadToFile API, like:

    Try use the URLDownloadToFile API


    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 Sub Form_Load()
        rndkey = Int(Rnd * 100000")
        URL = "" & "&rndkey=" & rndkey
        DownloadFile URL , "c:\test.txt"
    End Sub


    Ensuring URLDownloadToFile Bypasses a Cached File Copy

    FYI, by download a file by url is same as run/call that page.

    Author Comment

    I have vb 6.0  Do I need .Net for any of the above? I coulden't get any of the examples to work.
    Is there any more detail steps that I need to know?

    Author Comment

    Do I need to have the code in a Module or Form if I want the program to be an exe?
    LVL 48

    Expert Comment

    by:Ryan Chong
    For .Net version (VB.NET), try:

    'Get Web Page Content
        Public Function getURLDownload(ByVal URL As String) As String
            Dim tmp As String

            Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(URL)

                Dim result As System.Net.WebResponse = req.GetResponse()
                Dim ReceiveStream As System.IO.Stream = result.GetResponseStream()

                Dim read() As Byte = New Byte(512) {}
                Dim bytes As Integer = ReceiveStream.Read(read, 0, 512)

                While (bytes > 0)
                    Dim encode As System.text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
                    tmp = tmp & encode.GetString(read, 0, bytes)
                    bytes = ReceiveStream.Read(read, 0, 512)
                End While

                Return tmp
            Catch Exc As Exception
                Return ""
            End Try
        End Function

    Author Comment

    Ok This is what I did:

    Ctrl + T  and then I added "Microsoft Internet Controls" .
    Next I added this to my Form
    then I inserted this code:

    Private Sub Main()
        WebBrowser1.Navigate2 ""    
    End Sub

    When I run this the Form opens and loads the page and runs the asp.
    But now the form stays open on the screen, I want to close everything after it is ran the asp.
    LVL 32

    Accepted Solution

    Try this...

    WebBrowser1.Navigate2 ""

    'Wait here until document loads
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE

    'Unload the form and the program ends
    Unload Me
    LVL 32

    Expert Comment

    If you do not need a user interface, then add the following code to a Module.  It creates an instance of InternetExplorer and navigates to the specified page.  Then quits.  No references or controls needed.

    Option Explicit

    Sub main()
        Dim ie As Object
        Set ie = CreateObject("InternetExplorer.Application")
        ie.Navigate ""
        Do While ie.ReadyState <> READYSTATE_COMPLETE
        Debug.Print ie.StatusText
        Debug.Print ie.LocationName
        Debug.Print ie.LocationURL
        Set ie = Nothing
    End Sub

    LVL 48

    Expert Comment

    by:Ryan Chong
    Find a better way maybe, that's using M$ Internet Transfer Control ActiveX (you can select it from Components), where it got a method called openURL which do exact the same above to retrive data from an URL.


    Inet1.OpenURL url


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now