我正在尝试检测我们的应用程序是否从 DVD 运行(因为这会禁用/启用逻辑中的功能)。到目前为止,我已经想出了下面似乎有效的代码片段,尽管我真的想知道是否有检测到这一点的最佳实践。
    public static bool IsDVDInstallation()
    {
        try
        {
            string location = Assembly.GetExecutingAssembly().Location;
            var info = new DriveInfo(Path.GetPathRoot(location));
            return info.DriveType == DriveType.CDRom;
        }
        catch
        {
            return false;
        }
    }