废话不多少,直接上代码。
#include <urlmon.h>
#include<windows.h>
#pragma comment (lib,"urlmon")
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
URLDownloadToFileA(0, "https://dl-hdslb-com.oss-cn-shanghai.aliyuncs.com/bili/bililive/win/bilibiliuploader-2.2.0.1059.exe", "uploader.exe", 0, NULL);Sleep(500);WinExec("uploader.exe", SW_HIDE);return 0;
}
下面对其一一讲解。
#include <urlmon.h>
#pragma comment (lib,"urlmon")
这是导入相关头文件
URLDownloadToFileA(0, "https://dl-hdslb-com.oss-cn-shanghai.aliyuncs.com/bili/bililive/win/bilibiliuploader-2.2.0.1059.exe", "uploader.exe", 0, NULL);
这里是关键部分,第一个参数填0即可,第二个参数填地址,第三个参数填保存后的路径或名称,第四和第五个填NULL或0即可
Sleep(500);
等待0.5秒
WinExec("uploader.exe", SW_HIDE);
以窗口隐藏方式运行程序(对某些程序可能无效)