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;
}