vb.net 下载一个文件然后执行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14522716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:37:27  来源:igfitidea点击:

Download a file and then execute it

vb.netdownload

提问by user1970090

I'm creating an application that downloads some applications (like FireFox, WinRar, RealPlayer) and then install them silently using Shell command. This is the code:

我正在创建一个应用程序,用于下载一些应用程序(如 FireFox、WinRar、RealPlayer),然后使用 Shell 命令静默安装它们。这是代码:

My.Computer.Network.DownloadFile("URL", "path\file.exe")
Shell("path\file.exe /s")

The problem is that the shell command starts before Download Is completed, so I get a "file not found" error. So my questions are:

问题是 shell 命令在下载完成之前启动,所以我收到“找不到文件”错误。所以我的问题是:

  1. How can I execute Shell command after the download is completed?
  2. Can I use process.start with Sparameter instead of Shell command?
  1. 下载完成后如何执行Shell命令?
  2. 我可以使用带有S参数的process.start而不是 Shell 命令吗?

回答by SysDragon

This should do the trick to download the file and wait until its over:

这应该可以下载文件并等待它结束:

Dim wc As WebClient = New WebClient()
wc.DownloadFile(sURL, sFile)