FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

modifiying the windows registry with the windows API - run

 


acromm
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)

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
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.