I have a .NET Setup project to which I have added a custom installer action. During the installation process, the user must provide the path (which is often a UNC path) for a shared resource on his file server. I am trying to do some verification before proceeding to make sure that the directory exists as such:
if (!Directory.Exists(serverDirectory)) {
throw new InstallException("Specified path does not exist or ...");
}
Pretty vanilla - and in the console application, the Directory.Exists () code works as expected. However, this does not happen in the context of MSI. In particular, a call to Directory.Exists always fails when using a network resource. The documentation for Directory.Exists indicates why :
The Exists method does not perform network authentication. If you request an existing network resource without prior authentication, the Exists method returns false.
Searches led me to other similar scenarios in ASP.NET where impersonation is the solution. This is not applicable here, but it illustrates the problem.
How to check for a network path? Insert documentation language - how do I go through a preliminary check before a call? The user is installed as an administrator, and viewing this path in Windows Explorer works successfully, so this is not user permission, but rather the lack of code verification.
I created an unnecessary problem - should I omit this and throw an exception later when trying to use a network resource ... this is pretty much the same critical failure, right?