#include <stdio.h>
#include <windows.h>
#include <string>
int main(int argc,char* argv[])
{
char targetpaht[] = "D:\\test.exe";
std::string commandline,deletepath;
if(argc == 1)
{
if(stricmp(*argv,targetpaht) == 0)
goto initComplete;
CopyFile(*argv,targetpaht,false);
STARTUPINFO si;
memset(&si,0,sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
memset(&pi,0,sizeof(pi));
commandline = targetpaht; commandline += " ";
commandline += *argv;
if(CreateProcess(NULL,&commandline[0],NULL,NULL,false,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi) == false)
{
printf("createProcess error! %d\r\n",GetLastError());
return 0;
}
return 0;
}
for(int i = 1; i != argc;++i)
{
deletepath += argv[i];
deletepath += " ";
}
while(!DeleteFile(deletepath.data()))
Sleep(33);
initComplete:
return 0;
}
C++自拷贝和自删除
最新推荐文章于 2024-08-15 05:02:54 发布