简体   繁体   English

如何在vb.net中下载exe文件(Visual Studio 2015)

[英]how to download exe files in vb.net (Visual Studio 2015)

I try make one program for download one .exe file and run for help in my job. 我尝试制作一个程序来下载一个.exe文件,然后运行以寻求帮助。 But idk how to make this, i'm new in VB. 但是idk如何做到这一点,我在VB中是新手。

I am using this code, as shown in the Visual Basic document reference : 我正在使用此代码,如Visual Basic文档参考中所示

My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/WineList.txt", _
"C:\Documents and Settings\All Users\Documents\WineList.txt")

But when I try to download an .exe file, the entire file doesn't complete and I the file is only 1 kb after download. 但是,当我尝试下载.exe文件时,整个文件未完成,下载后我只有1 kb。

The webclient should be the way to go a comment above highlights that too. Webclient应该是上面注释的一种方式,这也突出了这一点。

This is an example from another question: 这是另一个问题的示例:

Either use sync method: 使用同步方法:

public void DownloadFile()
{
    using(var client = new WebClient())
    {
        client.DownloadFile(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
    }
}

Or use new async-await approach: 或使用新的异步等待方法:

public async Task DownloadFileAsync()
{
    using(var client = new WebClient())
    {
        await client.DownloadFileTaskAsync(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
    }
}

Then call this method like this: 然后像这样调用此方法:

await DownloadFileAsync();

Open up the .exe file you are trying to download in a text editor like NotePad. 在文本编辑器(如NotePad)中打开要尝试下载的.exe文件。 Odds are what is being downloaded is an HTML page showing some kind of error message like 404 not found . 奇怪的是,正在下载的HTML页面显示出404 not found类似404 not found类的错误消息。

Another possibility might be that AntiVirus software is moving the original EXE into quarantine and replacing it with a Quarantine MetaData file. 另一种可能是AntiVirus软件将原始EXE移入了隔离区,并用隔离区MetaData文件替换了它。

If the file does actually contain binary content your connection could be getting interrupted but odds are if this happened an exception would be thrown. 如果文件确实包含二进制内容,则您的连接可能会中断,但如果发生这种情况,则可能会引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2015(VB.NET)中的“ TryCF” - “TryCF” in Visual Studio 2015 (VB.NET) 如何在Visual Studio 2015中更改VB.NET语言版本 - How to change the VB.NET language version in Visual Studio 2015 防止 Visual Studio 2015 删除 VB.NET 文件中的行继续符 (_) - Prevent Visual Studio 2015 from removing line continuation characters (_) in VB.NET files vb.net visual studio 2015本地化应用程序安装项目 - vb.net visual studio 2015 setup project of localized application 在 Visual Studio 2015 中使用 VB.NET 发送 Outlook 邮件 - Sending outlook mail using VB.NET in Visual Studio 2015 在Visual Studio 2015(社区)中集成VB.NET和Flash - Integrating VB.NET with Flash in Visual Studio 2015 (Community) 使用Visual Studio 2015的VB.NET安装程序包 - VB.NET Installer Package using Visual Studio 2015 使用Visual Studio 2015更新Access数据库-VB.net - Update Access database using Visual Studio 2015 - VB.net 如何在vb.net中使用ado.net在Visual Studio 2015中执行MDX查询 - How to execute a MDX Query in Visual studio 2015 using ado.net in vb.net 如何在VB.NET for Visual Studio 2015中显示片段? - How do you make snippets show in VB.NET for Visual Studio 2015?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM