Solved

HELP: Can't write a text file from a NT Service

Posted on 2002-07-17
11
205 Views
Last Modified: 2010-04-01
I'm trying to open and write to a text file to be used as a service logfile, the file is opened when entering the service and should be available to all the threads the service creates.
I've create a CLogFile that simply opens the file anda provides a method to format the text before writing, it uses the CreateFile and WriteFile functions.
Somehow nothing happens, it doesn't open the file, doesn't write... even when the file is opened inside a thread the result is the same, creates a 0 byte file and the WriteFile function doesn't write.
Like the old Beetles song: HELP :)
0
Comment
Question by:JoaoMota
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 7159104
what does WriteFile return ? have you checked what GetLastError() return ?

can post the code where you are writing to file
0
 

Author Comment

by:JoaoMota
ID: 7159130
I forgot to mention: when running the service as normal app the logfile works as expected, only when running as a service it does nothing.

i use the following code in the OpenLog method:
hLogFile = CreateFile(acFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,  FILE_ATTRIBUTE_NORMAL, NULL );

and the following in the WriteLog method:
WriteFile((HANDLE)hLogFile, cLogString, strlen(cLogString), &nWritten, NULL);
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7159325
Are you using an absolute path name in 'acFile'? If not, take a look into '%WINNT%\System32', you might find the file there :o)
0
 

Expert Comment

by:gemme
ID: 7159542
Try closing the file and see if it then populates it.  I had a similiar issue with NT and found that the file will not write until it is closed.
0
 

Author Comment

by:JoaoMota
ID: 7159954
guys.... thank you all, but i've found the problem (some $#%&#$#$$#% hard-coded a absolute path in one of the custom lib we use here... once again thank you all.

Joao - portuguese food&wine fan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 7159972
>>thank you all, but i've found the problem

Then you should reject the proposed "answer" and ask CS to delete this Q...
0
 
LVL 30

Expert Comment

by:Axter
ID: 7160433
Hi (gemme), welcome to EE.

All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.

An answer should not be posted as an answer, if other experts have previously posted possible answers as comments, and/or have already made contributions to the question.

There are many experts who never post answers as answer.  Instead, they post their answers as comments.

If you read the following link, you'll see why this is the preferred method for many of our valued experts, including myself.

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Hi (JoaoMota):
Feel free to click the [Reject Answer] button near (Answer-poster's) response, even if it seems like a good answer.
Doing so will increase your chance of obtaining additional input from other experts.  Later, you can click the [Select Comment as Answer] button on any response.
0
 
LVL 11

Expert Comment

by:griessh
ID: 7376080
Dear JoaoMota

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to

     "refund the points and delete this question"

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 86

Expert Comment

by:jkr
ID: 7376653
Me:
>>Are you using an absolute path name in 'acFile'?

JoaoMota:
>>guys.... thank you all, but i've found the problem (some
>>$#%&#$#$$#% hard-coded a absolute path in one of the
>>custom lib we use here

It sounded like "answered" to me :o)
0
 
LVL 11

Expert Comment

by:griessh
ID: 7376870
Sorry, I missed your comment about the absolute path name.

I will suggest to accept

    "jkr"

comment as an answer.

======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7419907
Force accepted

** Mindphaser - Community Support Moderator **

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now