first commit

This commit is contained in:
winsbu1997 committed 2025-07-03 08:48:49 +07:00
commit 55eb9666e9
10 files changed
+929

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include <windows.h>
#include <tchar.h>
int addregistry(LPCWSTR filetarget, LPCWSTR nameReg)
{
// Đường dẫn tới file exe
const TCHAR* exePath = filetarget;
// Tên registry key
const TCHAR* regKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
// Tên giá trị registry
const TCHAR* valueName = nameReg;
// Mở khóa registry
HKEY hKey;
LONG result = RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_SET_VALUE, &hKey);
if (result != ERROR_SUCCESS) {
_tprintf(_T("Không thể mở khóa registry. Lỗi: %ld\n"), result);
return 1;
}
// Đặt giá trị cho registry key
result = RegSetValueEx(hKey, valueName, 0, REG_SZ, (const BYTE*)exePath, (_tcslen(exePath) + 1) * sizeof(TCHAR));
if (result != ERROR_SUCCESS) {
_tprintf(_T("Không thể đặt giá trị registry. Lỗi: %ld\n"), result);
RegCloseKey(hKey);
return 1;
}
// Đóng khóa registry
RegCloseKey(hKey);
_tprintf(_T("Đã thêm vào registry key thành công.\n"));
return 0;
}