S
S
sabes2021-04-14 19:30:07
C++ / C#
sabes, 2021-04-14 19:30:07

Why doesn't C++ program autorun work?

To start the program when loading Win, I wrote this code. The entry appeared in the registry, and the corresponding program appears in the Startup Task Manager (Status Enabled). But when you reboot, the launch does not occur (otherwise, the program works as it should). An entry appears in the Win log:

Faulting Application Name: init.exe, Version: 0.0.0.0, Timestamp: 0x6076a6d6 Faulting Module
Name: msvcrt.dll, Version: 7.0.19041.546, Timestamp: 0x564f9f39 Exception
Code: 0xc0000005 Error
Offset: 0x000000000005a33a
Failed Process ID: 8dx0
s2 Faulting Application Startup: 0x01d731081595a738 Faulting Application
Path: C:\Users\Lol\AppData\Roaming\CS\init.exe Faulting Module
Path: C:\Windows\System32\msvcrt.dll
Report ID: acaa45c7-8249-4db7-b88f- 6a08916a237c
Full name of the failed package:
Application code associated with the failed package:


The code itself:

char *my_path = "C:\\Users\\Lol\\AppData\\Roaming\\CS\\init.exe";
        HKEY hKey;
        RegCreateKeyEx(HKEY_CURRENT_USER,
                         "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
                         NULL,
                         "",
                         REG_OPTION_NON_VOLATILE,
                         KEY_ALL_ACCESS,
                         NULL,
                         &hKey,
                         NULL);

        if (hKey)
        {
            RegSetValueEx(hKey, "CSInit", NULL, REG_SZ, (PBYTE)my_path, lstrlen(my_path));
            RegCloseKey(hKey);
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petryaev, 2021-04-16
@Gremlin92

Build the program not in Debug, but in Release

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question