none
Cannot download file from internet using Windows Server 2008 and Lib urlmon RRS feed

  • Question

  • I got this from another thread here.  It works on Windows 8, but not on my servers. Does anyone know another way to download files from the internet or maybe why this wouldn't work on the Windows Server 2008?

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
    ' Some pages may also contain other copyrights by the author.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Distribution: You can freely use this code in your own
    '               applications, but you may not reproduce
    '               or publish this code on any web site,
    '               online service, or distribute as source
    '               on any media without express permission.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    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
       
    Private Const ERROR_SUCCESS As Long = 0
    Private Const BINDF_GETNEWESTVERSION As Long = &H10
    Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
    
    Private Sub Form_Load()
    
       Command1.Caption = "Download File"
       
    End Sub
    
       
    Private Sub Command1_Click()
    
       Dim sSourceUrl As String
       Dim sLocalFile As String
       Dim hfile As Long
       
       sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm"
       sLocalFile = "c:\users\support\desktop\deleteme.htm"
       
       Label1.Caption = sSourceUrl
       Label2.Caption = sLocalFile
       
       If DownloadFile(sSourceUrl, sLocalFile) Then
       
          hfile = FreeFile
          Open sLocalFile For Input As #hfile
             Text1.Value = Input$(LOF(hfile), hfile)
          Close #hfile
          
       End If
    
    End Sub
    
    
    Public Function DownloadFile(sSourceUrl As String, _
                                 sLocalFile As String) As Boolean
      
      'Download the file. BINDF_GETNEWESTVERSION forces
      'the API to download from the specified source.
      'Passing 0& as dwReserved causes the locally-cached
      'copy to be downloaded, if available. If the API
      'returns ERROR_SUCCESS (0), DownloadFile returns True.
       DownloadFile = URLDownloadToFile(0&, _
                                        sSourceUrl, _
                                        sLocalFile, _
                                        BINDF_GETNEWESTVERSION, _
                                        0&) = ERROR_SUCCESS
       
    End Function

    Thursday, September 22, 2016 1:38 PM

Answers

  • It was software on the Windows 2008 Server restricting website access. Silly me!  Sorry. I would remove this thread but I don't see that option.
    • Marked as answer by Love2Code2Much Thursday, September 22, 2016 2:26 PM
    Thursday, September 22, 2016 2:26 PM

All replies

  • Hi Love2Code2Much,

    Could you please post an example of the error you are getting?

    Cheers

    Anthony

    Thursday, September 22, 2016 1:44 PM
  • It was software on the Windows 2008 Server restricting website access. Silly me!  Sorry. I would remove this thread but I don't see that option.
    • Marked as answer by Love2Code2Much Thursday, September 22, 2016 2:26 PM
    Thursday, September 22, 2016 2:26 PM