#include<windows.h>#include<iostream>#include<fstream>voidUpgradeService::UpgradeSelf(){std::stringtemp=root+"\\myprogram_tmp.exe";remove(temp.c_str());// ignore return codestd::stringsrc=upgradeFolder+"\\myprogram.exe";std::stringdst=root+"\\myprogram.exe";rename(dst.c_str(),temp.c_str());CopyFile(src.c_str(),dst.c_str(),false);staticcharbuffer[512];strcpy(buffer,dst.c_str());/* CreateProcess API initialization */STARTUPINFOsiStartupInfo;PROCESS_INFORMATIONpiProcessInfo;memset(&siStartupInfo,0,sizeof(siStartupInfo));memset(&piProcessInfo,0,sizeof(piProcessInfo));siStartupInfo.cb=sizeof(siStartupInfo);::CreateProcess(buffer,// application name/pathNULL,// command line (optional)NULL,// no process attributes (default)NULL,// default security attributesfalse,CREATE_DEFAULT_ERROR_MODE|CREATE_NEW_CONSOLE,NULL,// default envNULL,// default working dir&siStartupInfo,&piProcessInfo);::TerminateProcess(GetCurrentProcess(),0);::ExitProcess(0);// exit this process// this does not return.}