在工程的cpp文件中WinMain还是得最后添加如下的代码(其中g_blsRunAgain为bool类型的全局变量,在需求重启的时候先将g_blsRunAgain置为true,再将程序关闭,之后就会重启):

    //------重启自身-----------------
    if(g_blsRunAgain)
    {
       AnsiString strPath;
       STARTUPINFO StartInfo;
       PROCESS_INFORMATION procStruct;
       memset(&StartInfo,0,sizeof(STARTUPINFO));
       StartInfo.cb = sizeof(STARTUPINFO);
       strPath = Application->ExeName;
       if(!::CreateProcess(
             (LPCTSTR)strPath.c_str(),
             NULL,
             NULL,
             NULL,
             False,
             NORMAL_PRIORITY_CLASS,
             NULL,
             NULL,
             &StartInfo,
             &procStruct))
      {
         return 0;
      }
    }
    //--------------------------------

    return 0;//main函数原有的返回代码