?
Solved

Windows service application

Posted on 2003-03-12
9
Medium Priority
?
651 Views
Last Modified: 2012-05-04
Hi experts,

 I am doing a windows service application. I had to validate some fields given in a ini file before starting the service. I came accross a problem i hope u people can find a solution for. I have to check the existance of a network path, I am using the directoryexists function to check for the existance of a network path but i am getting a result of false eventhough this path exists. Can any one help me out.

I am giving the code

Function CreateDirIfNotExists(const Dir : String) : Boolean;
Begin
  CreateDirIfNotExists := False;
  ForceDirectories(Dir);
  If Not DirectoryExists(Dir) Then
    Exit;
  CreateDirIfNotExists := True;
End;

Begin
......
....
...
  DataFilesDir := '\\server01\d_drive\data\site1';
  if not CreateDirIfNotExists(DataFilesDir) then
  begin
    MessageStr := GetApplMsgStr(7) + DataFilesDir + Chr(0);
    AuditLog(MessageStr, ltSystem);
    Exit;
  End;
....
.....
......
End;


Regs,
Kalazar
0
Comment
Question by:kalazar
8 Comments
 
LVL 1

Expert Comment

by:pede
ID: 8118362
If you are doing the check from inside the service it will fail because the service runs as system account, and cannot access net work drives.

0
 

Author Comment

by:kalazar
ID: 8118391
hi.

 ya i am doing it from within the service. is there any solution.

Regs
Kalazar
0
 
LVL 1

Accepted Solution

by:
pede earned 400 total points
ID: 8118419
You could run the whole service as a user, thats the easiest solution (Services/Log on), or you could play around with LogonUser and ImpersonateLoggedOnUser. I never tried using ImpersonateLoggonUser, but this search

http://www.google.com/search?hl=da&ie=UTF-8&oe=UTF-8&q=site%3Awww.experts-exchange.com+impersonateloggedonuser+delphi&lr=

on Google will give you some other interesting Q's here at EE. Good luck ;)
0
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!

 
LVL 6

Expert Comment

by:DaFox
ID: 8118507
Yep, pede is right. Network mappings are set up as soon as an user logs on. Since the default user for service applications is LocalSystem the network drives are probably not "mapped".
Run your service under an user account (you can set this when calling CreateService()).

Markus
0
 
LVL 1

Expert Comment

by:pede
ID: 8118529
>Since the default user for service applications is LocalSystem the network drives are probably not "mapped".

I remember reading somewhere that security issues are the reason why system account doesnt have network access.
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8118627
That's possible. That was just my suggestion. However, logging on as an user should do it.

Markus
0
 

Expert Comment

by:CleanupPing
ID: 9316824
kalazar:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10095971
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: pede

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0

Featured Post

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!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

580 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