The program can read the configuration in the Config.ini file in the same directory to enable boot.
The Config.ini file format instance is as follows:
[Main]
KeyName = Test
Processpath = D:\bin\test.exe
Where the KeyName field is the table key name written to the registry (can be set to the program name)
Processpath the full path to the program
The complete source code for the program is as follows.
The Regedit function implements the registry write, and the autopen implements the boot from boot.
The compiled program is downloaded here: Program Download
#include <stdio.h> #include <windows.h>int regedit (HKEY key, const char* reg_name, const char* key_name, const char* key_value) {HKEY hkresult; int Ret=regopenkeyex (key, Reg_name, 0, Key_all_access, &hkresult), if (ret! = 0) return Ret;ret=regsetvalueex ( Hkresult, Key_name, 0, REG_EXPAND_SZ, (CONST byte*) Key_value, + if (ret==0) {RegCloseKey (hkresult); return 0;} else{return ret;}} int autopen (const char* key_name, const char* process_path) {char reg_name[] = "software\\microsoft\\windows\\ Currentversion\\run "; return regedit (HKEY_LOCAL_MACHINE, Reg_name, Key_name, Process_path);} int main (void) {char Key_name[100];char process_path[1000]; Getprivateprofilestringa ("Main", "KeyName", "Test", Key_name, sizeof (Key_name), ". \\config.ini"); Getprivateprofilestringa ("Main", "Processpath", "Test", Process_path, sizeof (Process_path), ". \\config.ini"); int ret = Autopen (Key_name, Process_path), if (ret = = 0) printf ("Write to register succeed\n"); elseprintf ("Write to register failed \ n ");System ("pause"); return 0; }