?
Solved

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

Posted on 2002-07-17
11
Medium Priority
?
235 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 800 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

752 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