Solved

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

Posted on 2002-07-17
11
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

707 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