Implement Software Automatic startup code

Source: Internet
Author: User
Auto Start Code :

Void cserverapp: setautorun ()

{

Hkey;

Char * szregpath = "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run ";

Long LRET;

// Open the Registry

LRET = regopenkeyex (HKEY_LOCAL_MACHINE, szregpath, 0,

Key_all_access, & hkey );

If (LRET! = Error_success)

{

Afxmessagebox ("An error occurred while enabling automatic Registry Startup! ");

Regclosekey (hkey );

Return;

}

// Obtain the path of the current file

Char szfilepath [max_path];

DWORD dwret;

Dwret = getmodulefilename (null, szfilepath, max_path );

If (dwret = 0)

{

Afxmessagebox ("failed to get the current file path! ");

Return;

}

// Add the current path to the Registry

LRET = regsetvalueex (hkey, "attendserver", 0, REG_SZ,

(Const byte *) & szfilepath, strlen (szfilepath) + 1 );

If (LRET! = Error_success)

{

Afxmessagebox ("An error occurred while writing to automatically start the registry! ");

Regclosekey (hkey );

Return;

}

Regclosekey (hkey );

}

Cancel the automatic run code:

Void cserverapp: cancelautorun ()

{

Hkey;

Char * szregpath = "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run ";

Long LRET;

// Open the Registry

LRET = regopenkeyex (HKEY_LOCAL_MACHINE, szregpath, 0,

Key_all_access, & hkey );

If (LRET! = Error_success)

{

Afxmessagebox ("An error occurred while enabling automatic Registry Startup! ");

Regclosekey (hkey );

Return;

}

LRET = regdeletevalue (hkey, "attendserver ");

If (LRET! = Error_success)

{

Afxmessagebox ("An error occurred while deleting the software during Automatic startup of registry settings! ");

Regclosekey (hkey );

Return;

}

Regclosekey (hkey );

}

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.