Link to home
Start Free TrialLog in
Avatar of cero
cero

asked on

Working Directory in a NT Service

Hi,

I don't know how to read the directory where the Exe File is located. Well, whenever I try to get the current directory, using GetCurrentDirectory or _getcwd, I get C:\WINNT\System32 but my file is located in another location. I read something about Get


Any idea??
Thanxs
cero
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhance
jhance

You have 2 options:

1) In your service, change the current directory to where you need it to be.  Usually you will use SetCurrentDirectory() to do this.

2) Access your file using an ABSOLUTE file name.  I.e. specify entire PATH to the file.
I used to use GetModuleFileName function:
char buf[MAX_PATH];
if (!::GetModuleFileName(0, buf, MAX_PATH))
{
// handle error
}

// buf contains the full path including file name
// trim file name and you will get the current directory
Avatar of cero

ASKER

to jhance:

1) and 2) I'm doing that and I want to change that.

to jkr:
I will prove that.

to YuriPutivsky:
It's the same? it isn't?

thanks to all
cero.
Yes it does,
Sorry "jkr" I didn't refresh IE screen before sending comment and didn't see your comment...