?
Solved

Windows service application

Posted on 2003-03-12
9
Medium Priority
?
646 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
[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
9 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

801 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