views:

210

answers:

2

I have used SUSBST command to create mapped drive to a certain folder. In a console application I can access the directory, while I cant access the same directory in a windows service application. In other words the following line returns false

Directory.Exists(@"x:\directory")

where x: is defined using SUBST as follow:

SUBST x: c:\xdrive

How can I access the subst-mapped directories in a windows service application?

+1  A: 

Subst lives in your registry hive. The windows service must be running as you to access this. Change the crendentials of the service.

If this is not possible then you could programmatically create a link to the location. Such as by calling System.Process to run a cmd.exe /c subst command.

Preet Sangha
i'm afraid my application doesn't know the original place of the directory in order to run susbst command! it only knows d: drive, and it doesn't care where it is mapped to. Is there a way to resolve the original mapped location of a drive created by SUBST commmand?
ala
A: 

If your service runs as Local System follow the instructions here:

http://blogs.msdn.com/b/adioltean/archive/2004/11/29/271987.aspx

That will get you a command prompt running as local service to take your subst command

Adam