VC + + Programming to achieve boot start

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.