请问下exe主要做了哪些功能
Opened this issue · 13 comments
请问下exe主要做了哪些功能
@NeverMore-KL
请问下exe主要做了哪些功能
Electron应用关闭后启动EXE程序,EXE会在5秒后替换asar文件
@NeverMore-KL
请问下exe主要做了哪些功能
Electron应用关闭后启动EXE程序,EXE会在5秒后替换asar文件
exe程序能开源么?!
可以,我一会提交。
@xiaoping6688 等待中...我写了一个c的版本 打包后 15kb
已经提交 Source&README
@NeverMore-KL
请问下exe主要做了哪些功能
Electron应用关闭后启动EXE程序,EXE会在5秒后替换asar文件
替换后能自动启动就好了!
@xiaoping6688 可以啊 你再加一段代码
string asarSource = "";
string asarTarget = "";
System.Threading.Thread.Sleep(5000);
if(args.Length == 3)
{
try {
asarSource = args[0];
asarTarget = args[1];
System.IO.FileInfo fileInfoSrc = new System.IO.FileInfo(asarSource);
System.IO.FileInfo fileInfoDest = new System.IO.FileInfo(asarTarget);
if (!fileInfoSrc.Exists) Environment.Exit(1);
if (fileInfoDest.Exists)
{
System.IO.File.Copy(asarSource, asarTarget, true);
System.IO.File.Delete(asarSource);
}
else
{
System.IO.File.Move(asarSource, asarTarget);
}
using (Process exeProcess = new Process())
{
exeProcess.StartInfo.FileName = args[2];
exeProcess.Start();
}
}
catch(Exception e){
Console.WriteLine(e.Message);
}
}
else
{
Environment.Exit(1);
}
我自己也写了一个类似的,但是最后卡在不能替换。
大佬是弄多一个exe文件来执行替换的。这个思路不错,我也要写个简单的执行脚本来执行改名操作了,但是为什么要在5秒后才执行呢?
嗯 win下 文件是被进程占用的
用一个可视化ui 体验会好一些(比如WPF)
之前的命令行 被PO吐槽像在跑木马植入。
�
嘿嘿,拿了这个模块用在我的app,我把updater.cs翻译成了c++版本的,效果一样,好处是不依赖.net。
`//updater.cpp
//编译命令:cl -nologo -EHsc -GR -Zc:forScope -Zc:wchar_t -Feupdater /MANIFESTUAC:NO updater.cpp
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <Winuser.h>
#include <stdio.h>
#include <stdlib.h>
#include
#include
#pragma comment(linker, ""/manifestdependency:type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='' publicKeyToken='6595b64144ccf1df' language=''"")
#pragma comment(lib, "wsock32.lib")
#pragma comment(lib, "Kernel32.LIB")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
using namespace std;
#define FLUSH_NUM 8192
int main(int argc, char **argv)
{
std::string updateAsar = "";
std::string appAsar = "";
std::cout << "updater running!\n";
HWND hWnd = GetConsoleWindow();
// wait for the Electron app to close (5 secs)
Sleep(5000);
//ShowWindow(hWnd, SW_HIDE);
if (argc >= 3)
{
updateAsar.append(argv[1]);
appAsar.append(argv[2]);
cout << "copy " << updateAsar.c_str() << " to " << appAsar.c_str() << endl;
ifstream in(updateAsar, ios::binary);
ofstream out(appAsar, ios::binary);
if (!in)
{
printf("open file error");
return -1;
}
char flush[FLUSH_NUM];
while (!in.eof())
{
in.read(flush, FLUSH_NUM);
out.write(flush, in.gcount());
}
printf("copy done\n");
in.close();
out.close();
printf("unlink %s\n", argv[1]);
remove(updateAsar.c_str());
STARTUPINFO si = {sizeof(si)};
DWORD dwExitCode;
PROCESS_INFORMATION procInfo = {0};
if (argc == 4)
{
printf("run new app %s\n", argv[3]);
if (!CreateProcess(NULL,
argv[3],
NULL,
NULL,
FALSE,
0,
NULL,
NULL, &si, &procInfo))
{
printf("CreateProcess failed (%d)./n", GetLastError());
return 1;
}
else
{
CloseHandle(procInfo.hThread);
WaitForSingleObject(procInfo.hProcess, INFINITE);
GetExitCodeProcess(procInfo.hProcess, &dwExitCode);
CloseHandle(procInfo.hProcess);
}
}
}
else
{
return 1;
}
printf("Quit after 5 sec\n");
Sleep(5000);
return 0;
}`