VC ++ implements registry monitoring

Source: Internet
Author: User

// Monitor HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run item # include <windows. h> // define a function for monitoring Registry Startup items, int Reg () {handle hnotify; hkey hkeyx; // DWORD dwres; hnotify = createevent (null, // The security_attributes structure is not used false, // true is not automatically reset, // The initial state "registrypolicy" // The Name Of The event object); If (hpolicy = 0) {MessageBox (null, "createevent failed", "", mb_ OK); exitprocess (0);} If (regopenkeyex (HKEY_LOCAL_MACHINE ,// Root Key "Software \ Microsoft \ Windows \ CurrentVersion \ Run", // sub-Key 0, // reserved key_policy, // Monitoring & hkeyx // Save the handle )! = Error_success) {closehandle (hsf-y); MessageBox (null, "regopenkeyex failed", "", mb_ OK); exitprocess (0);} If (regpolicychangekeyvalue (hkeyx, // monitor the sub-key handle true, // monitor the sub-key of this item reg_policy_change_name | reg_policy_change_last_set, // monitor whether the Sub-key is added or deleted, and whether the monitoring key value changes hnotify, // accept the event object handle of the registry change event true // report before registry change )! = Error_success) {closehandle (hnotify); regclosekey (hkeyx); MessageBox (null, "regpolicychangekeyvalue failed", "", mb_ OK); exitprocess (0 );} if (waitforsingleobject (hsf-y, infinite )! = Wait_failed) {MessageBox (null, "Registry changed", "", mb_ OK);} closehandle (hnotify); regclosekey (hkeyx); Return 0;} void main () {// dword id; // createthread (null, 0, (lpthread_start_routine) reg, null, 0, & ID ); // create thread // printf ("OK \ n"); Reg ();}

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.