Use C + + Builder to add a startup log to your computer

Source: Internet
Author: User

Computers in a public room or office are commonly shared, and as managers or "primary" users want to know when a machine has been turned on and used, and if there is a startup record, it can be understood at any time. This article gives how to use C + + Builder 5 to achieve such a program, so that every time the computer to start the implementation of this program, in the registry to record the boot time information, so that the Registry Editor at any time to view. Program features: Every start of the computer to perform once (this function is automatically completed by this program without the need to manually add in the registry, just run a program can), in order to increase the concealment, the program for the background run of the No form program.

Programming Essentials:

1. Create a new project file in the C + + Builder 5 Environment: Execute the menu command file/new application, and then save the project file as "LOGON.BPR".

2. Execute menu command Project/view Source, open Logon.cpp file, put the

Useform ("Unit1.cpp", Form1);

and Application->createform (__classid (TFORM1), &form1);

Two statements are deleted in order to create a non-form program.

3. The full code for document Logon.cpp is as follows:

#include
#include//Add rows
#pragma hdrstop
Useres ("Logon.res");
WINAPI WinMain (hinstance, HINSTANCE, LPSTR, int)
{
Try
{//Add section Start
int num=0;
Tregistry *registry = new Tregistry; Create a registry Heap object pointer
Registry->rootkey = HKEY_USERS; Locate the registry root key
if (! Registry->openkey (". Default\\logon\\records ", false)
{//If opening primary key fails
Registry->createkey (". Default\\logon\\records "); Create PRIMARY key
if (!) ( Registry->openkey (". Default\\logon\\records ", false))
return 0;
Else
{
Tregistry *reg = new Tregistry; ①
Reg->rootkey = HKEY_LOCAL_MACHINE;
Reg->openkey ("Software\\microsoft\\windows\\currentversion\\run", false);
Reg->writestring ("Logon", application->exename); Register this program in the registry
Reg->closekey ();
Delete Reg;
Application->messagebox ("Login program registered successfully!") "," Results ", MB_OK); Ii
Registry->writeinteger ("power-on times", num);
Registry->writestring ("Program Registration Time", Date () +time ());
return 0;
}
}
Else
{
num = Registry->readinteger ("boot times"); ③
Registry->writeinteger ("Boot Times", num+1); Log boot times
Registry->writestring ("+ansistring" (num+1) + "secondary Boot", Date () +time ()); Log boot time
}
Registry->closekey ();
Delete Registry;
Add partial End
Application->initialize ();
Application->run ();
}
catch (Exception &exception)
{
Application->showexception (&exception);
}
return 0;
}

Related Article

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.