Hi,
im writting a code for count the reboots and shutdowns in windows7.
In the first run the program works fine, write the file and donīt show error msg. After a reboot or shutdown the program auto startup fine but donīt write the file.
the code:
ThanksCode:#include <stdio.h> #include <stdlib.h> #include <windows.h> //------------------------------------------------------------------------------ int s(void); int c(void); //------------------------------------------------------------------------------ int main(int argc, char *argv[]){ if(s()== 0) return 0; if(c()== 0) return 0; while(1){Sleep(100);} // view return function return 1; } //------------------------------------------------------------------------------ int s(void) { HKEY hkey; const char PATH[] = "C:\\Users\\User1\\Desktop\\reboot.exe"; // desk for now int regResult=RegOpenKeyEx(HKEY_CURRENT_USER/*HKEY_LOCAL_MACHINE*/, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_SET_VALUE,&hkey); if(regResult != 0) /*return 0;*/ printf("REG OPEN ERROR\n"); regResult=RegSetValueEx(hkey,"count",0,REG_SZ,(BYTE *)PATH, strlen(PATH)); if(regResult != 0) /*return 0;*/printf("REG SET ERROR\n"); regResult=RegCloseKey(hkey); if(regResult != 0) /*return 0;*/printf("REG CLOSE ERROR\n"); return 1; } //------------------------------------------------------------------------------ int c(){ FILE *counter; counter=fopen("filecounter.txt","a"); if(counter==NULL) /*return 0;*/ printf("FILE OPEN ERROR\n"); int check=fprintf(counter,"hello\n"); if (check==0) /*return 0;*/ printf("FPRINTF ERROR\n"); //int check = fputs("hello\n",counter); // donīt work //if (check!=0) return 0; // printf("FPUTS ERROR\n"); if(fclose(counter)!= 0) /*return 0;*/ printf("FCLOSE ERROR\n"); return 1; } //------------------------------------------------------------------------------
PS: The counting funcion is not write yet. Im just trying write the file.
PS2: Compiling with Dev-c++ 4.9.9.2, Windows7 Ultimate



LinkBack URL
About LinkBacks


