Solved

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

Posted on 2002-07-17
11
229 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
Technology Partners: 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 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