如何从服务器下载.MSI文件并从下载路径安装? [英] How to download .MSI file from server and install from download path?

查看:66
本文介绍了如何从服务器下载.MSI文件并从下载路径安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试下载.msi文件,其下载但是(它的大小为0字节)。我无法理解为什么会发生这种情况?请建议我正确的代码紧急。并建议如何通过c#代码安装下载的文件。



我尝试过:



private void btnUpdate_Click(object sender,EventArgs e)

{

string url = @http://www.http:// careusa。 co / update_files / PC_Cleaner.msi;

//创建WebClient实例

WebClient客户端=新WebClient();

// Hookup DownloadFileCompleted事件

client.DownloadFileCompleted + = new AsyncCompletedEventHandler(client_DownloadFileCompleted);



//开始下载并将文件复制到c: \ temp

client.DownloadFileAsync(new Uri(url),@C:\NewFolder \PC_Cleaner.msi); //路径 - 我要下载的地方---



}



void client_DownloadFileCompleted(object sender,AsyncCompletedEventArgs e)

{

MessageBox.Show(文件下载d);



string installerFilePath; //安装

installerFilePath = @C:\NewFolder \PC_Cleaner.msi;

System.Diagnostics.Process installerProcess;

installerProcess = System.Diagnostics.Process.Start(installerFilePath,/ q);

while(installerProcess.HasExited == false)

{

//表示用户进度

Application.DoEvents();

System.Threading.Thread.Sleep(250);

}

MessageBox.Show(完成安装);

}

I try to downlaod .msi file, its downloaded but (it size is 0 byte).I cannot understand why its happen? please suggest me correct code its urgent. And also suggest how to install downloaded file through c# code.

What I have tried:

private void btnUpdate_Click(object sender, EventArgs e)
{
string url = @"http://www.http://careusa.co/update_files/PC_Cleaner.msi";
// Create an instance of WebClient
WebClient client = new WebClient();
// Hookup DownloadFileCompleted Event
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

// Start the download and copy the file to c:\temp
client.DownloadFileAsync(new Uri(url), @"C:\NewFolder\PC_Cleaner.msi");//path-where i want to download---

}

void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("File downloaded");

string installerFilePath; //For install
installerFilePath = @"C:\NewFolder\PC_Cleaner.msi";
System.Diagnostics.Process installerProcess;
installerProcess = System.Diagnostics.Process.Start(installerFilePath, "/q");
while (installerProcess.HasExited == false)
{
//indicate progress to user
Application.DoEvents();
System.Threading.Thread.Sleep(250);
}
MessageBox.Show("done installing");
}

推荐答案

写一个正确的URL然后再试一次...... http://www.http:// [ ^ ]
write a correct URL then try again... http://www.http://[^]


这篇关于如何从服务器下载.MSI文件并从下载路径安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆