.netmapped-drive

SUBST and console app vs. windows service


I have used SUBST 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?


Solution

  • 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.