When writing the LAN monitoring System, the client program needs to be booted and implemented according to the following steps:
1. Add a member function to the main dialog class, write the registry, and set the boot from:
voidCclientdlg::setautorun (BOOL bautorun) {HKEY HKEY; CString Strregpath="Software\\microsoft\\windows\\currentversion\\run";//find the system's Startup items if(bautorun) {if(RegOpenKeyEx (HKEY_CURRENT_USER, Strregpath,0, key_all_access, &hkey) = = ERROR_SUCCESS)//Open Startup Item{TCHAR Szmodule[_max_path]; GetModuleFileName (NULL, Szmodule, _max_path);//get the full path of the program itselfRegSetValueEx (HKey,"Client",0, REG_SZ, (Constbyte*) (LPCSTR) Szmodule, strlen (Szmodule));//Add a child key and set the value, "Client" is the application name (without suffix. exe)RegCloseKey (HKey);//Close the registration table } Else{AfxMessageBox ("system parameter error, cannot be started with system"); } } Else { if(RegOpenKeyEx (HKEY_CURRENT_USER, Strregpath,0, key_all_access, &hkey) = =error_success) {Regdeletevalue (HKey,"Client"); RegCloseKey (HKey); } }}
2. Call the above function in the dialog initialization function Oninitdlg:
BOOL Cclientdlg::oninitdialog () { cdialog::oninitdialog (); // Add "About ..." menu item to System menu. . . . Setautorun (TRUE); // Set boot auto-start return TRUE;}
Compile and run, and when you restart the computer, the program starts automatically.
VC + + Programming to achieve boot start