防止从网络驱动器运行应用程序

时间:2016-02-01 13:38:31

标签: c# .net wpf

我想知道是否可以阻止或至少检测我的应用程序是否正在从网络驱动器而不是本地文件夹/驱动器中使用。

我希望告知我的用户他必须复制源并在本地运行它们,因为性能上存在严重缺陷。

1 个答案:

答案 0 :(得分:2)

获取path to where your executable has been executed,获取根,然后查明它是否为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.
}

请注意,您应该阅读我链接的问题(How can I get the application's path in a .NET console application?),因为它可能比上面的代码多一些,具体取决于您的具体情况。