[英]C Programming Writing to registry isn't working? Error at RegSetValueEX
嘗試將程序寫入Windows注冊表,但是我的代碼告訴我執行RegSetValueEX()
時出錯。 我具有管理權限。 我根本看不出有什么問題,而且整天都在盯着REG上的MSDN頁面。
int StartupKey()
{
int StartupKey;
long RegOpenResult, result_write;
const char *FilePath[]= "C:\\Windows\\security\\BensKlog.exe";
LPCSTR Klog = "BensKLOG";
HKEY hkey;
printf("Opening Key...\n");
RegOpenResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &hkey);
if(RegOpenResult != ERROR_SUCCESS) {
if(RegOpenResult == ERROR_FILE_NOT_FOUND) {
printf("Not found\n");
} else {
printf("Error Opening Key\n");
}
} else {
printf("SUCCESS!!!\n");
}
StartupKey=RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&hkey);
printf("Writing Value named Klog\n");
result_write = RegSetValueEx((HKEY)hkey,Klog,0,REG_SZ,(BYTE *)FilePath,strlen(FilePath));
if(result_write != ERROR_SUCCESS) {
printf("Error Writing Value\n");
} else {
printf("SUCCESS!!!\n");
}
RegCloseKey(hkey);
}
const char *FilePath[]= "C:\\Windows\\security\\BensKlog.exe";
使用以下任一方法:
const char FilePath[] = "C:\\Windows\\security\\BensKlog.exe";
要么
const char *FilePath = "C:\\Windows\\security\\BensKlog.exe";
但不要混用它們(您的代碼定義了一個const char指針數組而不是一個指針)。
(雖然可能不是唯一的錯誤)
告訴我大學的一名講師,向他展示了我聲稱我需要在管理員帳戶上運行的我的代碼,原來我筆記本電腦上的用戶不是管理員(我認為是)可以在我登錄時檢查它是否正常運行我的家和更新
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.