Windows Service - file writing.

Started by
2 comments, last by TelevirtualSoftDev 16 years, 10 months ago
I'm currently putting an application I have created into a windows service. I have a problem where ofstream does not appear to be working in my test service application. In this code example below, when I run from the services window, the FILE method writes to file but the ofstream does not although both work when run from VC++. Any help with this issue would be much apprecated. if(logging){ char* logNote = new char[1000]; TimeAndDate sysTime; sysTime.GetScreenTimeWithSeconds(logNote); strcat(logNote," - "); strcat(logNote,logInfo); strcat(logNote,"\n"); //findlogfilename char* logFileName = new char[500]; char* logDate = new char[500]; sysTime.GetDate(logDate); strcpy(logFileName,"RssServerLog"); strcat(logFileName,logDate); strcat(logFileName,".dat"); //open file where seek set at end,app - ignores any further seek command fstream logFile; logFile.open(logFileName, ios::app); logFile << logNote; logFile.close(); logFile.clear(); FILE* log; log = fopen("C:\\memstatus2.txt", "a+"); //if (log == NULL) //return -1; fprintf(log, "%s\n", logNote); fclose(log); }
Advertisement
Who is the service run as and can it interact with desktop? The stream may require a desktop environment though I do not know for certain.
Hi.

I've got it running under local system account with desktop access active so that i can debug it.

thanks for the reply
Hi.
I've solved this error.

I declared the variable as fstream - this works when opening the program normally but not when as a service. Need to use ofstream/ifstream.

Now it writes the file

This topic is closed to new replies.

Advertisement