[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Call an ASP file from an vb EXE

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?
Thanks
0
AutomaticSlim
Asked:
AutomaticSlim
  • 3
  • 3
  • 3
1 Solution
 
Erick37Commented:
Add a reference to "Microsoft Internet Controls" from the Project->References menu.
Place a Webbrowser control on your form.

Sub Form_Load()

Show
Doevents
Webbrowser1.Navigate2 "http://www.url.com/file.asp"

end Sub
0
 
Ryan ChongCommented:
try use URLDownloadToFile API, like:

Try use the URLDownloadToFile API

Example:

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()
    Randomize
    rndkey = Int(Rnd * 100000")
    URL = "http://www.abc.com/pass_management/user_auth.php?name=USERNAME&pass=PASSWORD" & "&rndkey=" & rndkey
    DownloadFile URL , "c:\test.txt"
End Sub

also:

Ensuring URLDownloadToFile Bypasses a Cached File Copy
http://vbnet.mvps.org/code/internet/urldownloadtofilenocache.htm

FYI, by download a file by url is same as run/call that page.
0
 
AutomaticSlimAuthor Commented:
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?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AutomaticSlimAuthor Commented:
Do I need to have the code in a Module or Form if I want the program to be an exe?
0
 
Ryan ChongCommented:
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)

        Try
            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
0
 
AutomaticSlimAuthor Commented:
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 "http://www.something.com/test.asp"   
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.
0
 
Erick37Commented:
Try this...

WebBrowser1.Navigate2 "http://www.microsoft.com"

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

'Unload the form and the program ends
Unload Me
0
 
Erick37Commented:
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 "http://msdn.microsoft.com"
    Do While ie.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    Debug.Print ie.StatusText
    Debug.Print ie.LocationName
    Debug.Print ie.LocationURL
    ie.Quit
    Set ie = Nothing
End Sub

0
 
Ryan ChongCommented:
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.

Example:

Inet1.OpenURL url

cheers
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now