Many times the system has a lot of configuration items, after modifying the configuration item can have a button to implement the system restart. The so-called restart is to kill the system's current process and then reopen a new process. Colleagues explored the implementation of this function. I summed up his experience. The following is an MFC dialog box program that describes how to implement the button response function.
[CPP] View plain copy// Restart button response function void ctestrebootdlg::onbnclickedreboot () { // TODO: Add control notification handler code here ::P ostmessage (AfxGetMainWnd ( )->m_hwnd,wm_syscommand,sc_close,null); //get EXE program current path extern CTestRebootApp theApp; TCHAR szappname[max_path]; :: getmodulefilename (theApp.m_hInstance, Szappname, max_path); CString strAppFullName; strappfullname.format (_t ("%s"), Szappname); //Restart program STARTUPINFO StartInfo; process_ information procstruct; memset (&startinfo, 0, sizeof ( Startupinfo)); startinfo.cb = sizeof (startupinfo); ::createprocess ( (LPCTSTR) Strappfullname, NULL, NULL, NULL, FALSE, normal_priority_class, NULL, NULL, &StartInfo, &procstruct); }
Reference documents:
1. How to restart the program automatically
2.windows Console Program Auto restart