VC ++ write registry self-start (switch)

Source: Internet
Author: User

Tchar m_filename [100];
// Cstring m_filename;
Getmodulefilename (null, m_filename, 100 );
Hkey;
Cstring STR = _ T ("software/Microsoft // windows // CurrentVersion // Run ");
If (error_success! = Regcreatekey (HKEY_LOCAL_MACHINE, STR, & hkey ))
{
MessageBox (_ T ("failed to open registry entry "));
Regclosekey (hkey );
Return;
}
Int length = 0;
While (m_filename [length]! = _ T ('/0 '))
Length ++;
If (error_success! = Regsetvalueex (hkey, _ T ("myautorun"), 0, REG_SZ, (const byte *) m_filename, sizeof (tchar) * length ))
{
MessageBox (_ T ("failed to write the Registry "));
Regclosekey (hkey );
}
Regclosekey (hkey );

Put the aboveCodeAdd to yourProgramAny place that can be executed.
If it is an MFC program, it does not need to contain any library files. Others should include <windows. h> and <tchar. h>
I successfully tested it in vc9.

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.