'Prevent application being runned from network drive

I wonder if it was possible to prevent or at least detect if my application is being used from a network drive instead of a local folder/drive.

I wish to inform my user that he has to copy the sources and run them locally because of heavy performance pitfalls.



Solution 1:[1]

Get the path to where your executable has been executed from, get the root, then find out if it is a network drive.

var root = Path.GetPathRoot(Assembly.GetEntryAssembly().Location)
var driveInfo = new DriveInfo(root));
if (driveInfo.DriveType == DriveType.Network) {
    // Alert that this will be slow.
}

Note that you should read the question I linked (How can I get the application's path in a .NET console application?), as there is potentially a bit more to it than the code above, depending on your exact scenario.

Solution 2:[2]

to prevent ArgumentException in case GetPathRoot returns \\Share\myshare

            DriveInfo driveInfo = null;

            try
            {
                driveInfo = new DriveInfo(Path.GetPathRoot(Assembly.GetEntryAssembly().Location));
            }
            catch (Exception)
            {
            }

            if (driveInfo == null || driveInfo.DriveType == DriveType.Network)
            {
                //not allowed
            }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 GioviQ