I make this function in c to add an entry in the windows registry, i hope it help. the objective is that my application or whatever run when windows initiate. Creates the key in the current user and in the local machine (for all users)
in the Main of your application or wherever you want, call the function with:
Switch the last parameter "1" for HKCU and "0" HKLM
| Code: |
|
#include <windows.h> //here i declare an array of characters with path of my application char exec[] = "C:\\myapplication.exe"; void CreateKey(char *destino,char *namekey,char *keyvalue,int que) { HKEY key; if (que == 0) { RegCreateKey(HKEY_LOCAL_MACHINE,destino,&key); RegSetValueEx(key,namekey,0,REG_SZ,(BYTE *)keyvalue,lstrlen(keyvalue)); RegCloseKey(key); } else if(que == 1) { RegCreateKey(HKEY_CURRENT_USER,destino,&key); RegSetValueEx(key,namekey,0,REG_SZ,(BYTE *)keyvalue,lstrlen(keyvalue)); RegCloseKey(key); } } |
in the Main of your application or wherever you want, call the function with:
| Code: |
|
CreaKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","My Application Name",exec,0); |
Switch the last parameter "1" for HKCU and "0" HKLM
