---
title: "最简单的从服务器下载文件的VB代码"
author: "hanbaohong"
date: "2010-04-15T22:54:06Z"
tags: ["C", "C#", "C++", "VB"]
categories: ["Web前端"]
slug: "vb"
draft: false
lastmod: "2010-04-15T23:05:19Z"
id: 645035
url: "https://hanbaohong.iteye.com/blog/645035"
---

第一种方法:后台下载

Private Declare Function URLDownloadToFile Lib "urlmon.dll" 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 Sub Command1\_Click()  
    URLDownloadToFile 0, "[http://192.168.1.101/hbwl.rar](http://192.168.1.101/hbwl.rar)", "c:\\hbwl.rar", 0, 0  
End Sub

 

 

第二种方法:文件另存为

Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long

Private Sub Command1\_Click()  
    Dim gourl As String  
    gourl = StrConv("[http://192.168.1.101/hbwl.rar](http://192.168.1.101/hbwl.rar)", vbUnicode)  
    Call DoFileDownload(gourl)  
End Sub