Access Volumn via extern and invoke win 32 dll

 const int SupportsCompression = 0x10;
        const int SupportEncryption = 0x20000;

        [DllImport("Kernel32.dll", SetLastError = true)]
        extern static bool GetVolumeInformation(string vol, StringBuilder name, int nameSize, out uint serialNum,
            out uint maxNameLen, out uint flags, StringBuilder fileSysName, int fileSysNameSize);

 static void GetVolumeInfoDemo()
        {
            uint serialNum, maxNameLen, flags;
            bool ok = GetVolumeInformation(@"C:", null, 0, out serialNum, out maxNameLen, out flags, null, 0);
            if(!ok)
            {
                throw new Win32Exception();
            }
            bool canCompress = (flags & SupportsCompression) != 0;
            Console.WriteLine($"canCompress:{canCompress}");
            bool canEncrypt = (flags & SupportEncryption) != 0;
            Console.WriteLine($"canEncrypt:{canEncrypt}");
        }
原文地址:https://www.cnblogs.com/Fred1987/p/13067621.html