作者 by Tokeii / 2020-08-03 / 暂无评论 / 2476 个足迹
上篇说到,用Web应用可以做到一件修复程序
这次我们来个进阶版本,让一键修复更方便
代码非常简单,就用c#随便写了下
第一个部分(启动部分),编译出来大概只有8kb左右,然后会自动下载指定软件,自动运行。其中/auto 为自解压参数可以双击之后自动解压不需要手动点击开始
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string HttpDownloadFile(string url, string path)
{
// 设置参数
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
return path;
}
private void Form1_Load(object sender, EventArgs e)
{
string downloadUrl = "这里填下载地址";//每次开启都会进行下载,所以可以一直保证软件的最新,即不需要更新程序
string filePath = "D:\\BaseFixPack.exe";
string downloadUrl2 = "这里填下载地址";
string filePath2 = "D:\\basepack\\Tools.exe";
HttpDownloadFile(downloadUrl, filePath);
HttpDownloadFile(downloadUrl2, filePath2);
Process.Start("D:\\BaseFixPack.exe", "/auto");
Thread.Sleep(5000);//等待5s
Process.Start("D:\\basepack\\Tools.exe");
System.Environment.Exit(0);//彻底退出工具
}
}
}
独特见解