0 overview
Software start-up is a more common practice, there are several ways to set up.
1 user mode
There is a startup folder in all Programs in the Start menu, which you can put in this folder for applications that need to be set up for boot. However, this is insufficient: the "Startup" folder path may be different on each computer and cannot be done once and for all.
Also, if you want to prevent the program from booting, you can either remove the corresponding program files from the Startup folder or manually set the "Win+r" Input "msconfig":
2 developer Mode
As a developer, of course, writing the registry is the best approach:
1. Create a new MFC application Autorun based on the dialog box;
2, add a CHECK box,id set to Idc_check_autorun, the text "boot from start ~";
3, add the private member variable in AutoRunDlg.h: int m_ncheakstate;
4. Start adding code at AutoRunDlg.cpp:
InlinevoidSetautorun () {TCHAR Szfilepath[max_path]; memset (Szfilepath,0, MAX_PATH); if(GetModuleFileName (NULL, Szfilepath, MAX_PATH)) {HKEY HKEY; CString Strregpath= _t ("Software\\microsoft\\windows\\currentversion\\run"); if(RegOpenKeyEx (HKEY_LOCAL_MACHINE, Strregpath,0, Key_set_value, &hkey) = =error_success) {RegSetValueEx (HKey, _t ("AutoRun"), 0, REG_SZ, (LPBYTE) Szfilepath, (Lstrlen (Szfilepath)+1)*sizeof(TCHAR)); } regclosekey (HKey); }}inlinevoidResetautorun () {HKEY HKEY; CString Strregpath= _t ("Software\\microsoft\\windows\\currentversion\\run"); if(RegOpenKeyEx (HKEY_LOCAL_MACHINE, Strregpath,0, Key_set_value, &hkey) = =error_success) {Regdeletevalue (HKey, _t ("AutoRun")); } regclosekey (HKey);}
5. Double-click the OK button to write the code:
CString strFilePath; TCHAR Szfilepath[max_path]; memset (Szfilepath,0, MAX_PATH); if(GetModuleFileName (NULL, Szfilepath, MAX_PATH)) {strFilePath=Szfilepath; strFilePath= Strfilepath.left (Strfilepath.reversefind ('\\')); strFilePath+ = _t ("\\AutoRun.ini"); } CButton* Pbtn = (cbutton*) GetDlgItem (Idc_check_autorun); intNcheakstate = pbtn->Getcheck (); if(M_ncheakstate! =ncheakstate) { if(Ncheakstate = =bst_unchecked) {Resetautorun (); WritePrivateProfileString (_t ("AutoRun"), _t ("AutoRun"), _t ("0"), strFilePath); } Else{setautorun (); WritePrivateProfileString (_t ("AutoRun"), _t ("AutoRun"), _t ("1"), strFilePath); } }
6. Compile and run:
Ps:
1, set the boot since the boot, I failed to find the registry key I set under Software\\microsoft\\windows\\currentversion\\run, restarted after the effective ~
2, the debug directory generated files, taskbar right-click Display "tod< File description >"
FileDescription has made changes in the version information, but it doesn't work, and I'm wondering ~
Move files in the Debug folder to a different directory to display the correct
The files in the compiled Release folder are also displayed correctly
VC + + Set up software boot from the method