protected override ExitCode ExecuteFileTask() { VolumeInformation info = ExtendedFileService.GetVolumeInformation(Arguments.Target); Table table = Table.Create(new ColumnFormat(1, ContentVisibility.ShowAll, Justification.Right), new ColumnFormat(1)); table.HasHeader = false; table.AddRow("Volume Name", info.VolumeName); table.AddRow("Serial Number", info.VolumeSerialNumber.ToString()); table.AddRow("Max Component Length", info.MaximumComponentLength.ToString()); table.AddRow("File System Name", info.FileSystemName.ToString()); foreach (var value in Enum.GetValues(typeof(FileSystemFeature))) { FileSystemFeature feature = (FileSystemFeature)value; if ((feature & info.FileSystemFlags) == feature) { table.AddRow(feature.ToString(), "true"); } else { table.AddRow(feature.ToString(), "false"); } } this.Loggers[LoggerType.Result].Write(table); return(ExitCode.Success); }
/// <summary> /// Obtains a users harddrive information. /// </summary> /// <param name="strRootDrive"></param> /// <returns></returns> private static object[] GetVolumeInfo(string strRootDrive) { try { StringBuilder sbVolume = new StringBuilder(261); StringBuilder sbName = new StringBuilder(261); FileSystemFeature fsFlags = 0; uint uiSerial = 0; uint uiMaxLen = 0; // Obtain Users Drive Information if (!GetVolumeInformation(strRootDrive, sbVolume, sbVolume.Capacity, out uiSerial, out uiMaxLen, out fsFlags, sbName, sbName.Capacity)) { throw new Exception("Failed to obtain drive information."); } // Build Return Value Array object[] objArray = new object[4]; objArray[0] = sbVolume.ToString(); objArray[1] = sbName.ToString(); objArray[2] = uiSerial.ToString(); objArray[3] = uiMaxLen; return(objArray); } catch { return(default(object[])); } }
public extern static bool GetVolumeInformation( string rootPathName, StringBuilder volumeNameBuffer, int volumeNameSize, out uint volumeSerialNumber, out uint maximumComponentLength, out FileSystemFeature fileSystemFlags, StringBuilder fileSystemNameBuffer, int nFileSystemNameSize);
private static extern bool GetVolumeInformation( string RootPathName, StringBuilder VolumeNameBuffer, int VolumeNameSize, out uint VolumeSerialNumber, out uint MaximumComponentLength, out FileSystemFeature FileSystemFlags, StringBuilder FileSystemNameBuffer, int nFileSystemNameSize);
public static extern bool GetVolumeInformation( string RootPathName, StringBuilder VolumeNameBuffer, int VolumeNameSize, out uint VolumeSerialNumber, out uint MaximumComponentLength, out FileSystemFeature FileSystemFlags, StringBuilder FileSystemNameBuffer, int nFileSystemNameSize);
extern static bool GetVolumeInformationByHandleW( SafeFileHandle RootPathName, StringBuilder VolumeNameBuffer, int VolumeNameSize, out uint VolumeSerialNumber, out uint MaximumComponentLength, out FileSystemFeature FileSystemFlags, StringBuilder FileSystemNameBuffer, int nFileSystemNameSize);
internal static extern bool GetVolumeInformationW( string lpRootPathName, SafeHandle lpVolumeNameBuffer, uint nVolumeNameSize, out uint lpVolumeSerialNumber, out uint lpMaximumComponentLength, out FileSystemFeature lpFileSystemFlags, SafeHandle lpFileSystemNameBuffer, uint nFileSystemNameSize);
internal extern static bool GetVolumeInformation( string RootPathName, StringBuilder VolumeNameBuffer, int VolumeNameSize, IntPtr VolumeSerialNumber, IntPtr MaximumComponentLength, out FileSystemFeature FileSystemFlags, IntPtr FileSystemNameBuffer, int nFileSystemNameSize);
public static extern bool GetVolumeInformationW( string lpRootPathName, SafeHandle lpVolumeNameBuffer, uint nVolumeNameSize, out uint lpVolumeSerialNumber, out uint lpMaximumComponentLength, out FileSystemFeature lpFileSystemFlags, SafeHandle lpFileSystemNameBuffer, uint nFileSystemNameSize);
public static void GetVolumeInformationOfPath(string itemPath, out string rootPathName, out string volumeName, out uint volumeSerialNumber, out FileSystemFeature features, out string fileSystemName, out uint maxComponentLength) { // Determine root path name: var rootPathNameBuilder = new StringBuilder(2000); Kernel32.GetVolumePathName(itemPath, rootPathNameBuilder, rootPathNameBuilder.Capacity); rootPathName = rootPathNameBuilder.ToString(); // Get volumen information: StringBuilder volumeNameBuilder = new StringBuilder(261); StringBuilder fileSystemNameBuilder = new StringBuilder(261); if (!Kernel32.GetVolumeInformation(rootPathNameBuilder.ToString(), volumeNameBuilder, volumeNameBuilder.Capacity, out volumeSerialNumber, out maxComponentLength, out features, fileSystemNameBuilder, fileSystemNameBuilder.Capacity)) Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); volumeName = volumeNameBuilder.ToString(); fileSystemName = fileSystemNameBuilder.ToString(); }
/// <summary> /// ボリュームの情報を取得する /// </summary> /// <param name="RootPathName"></param> /// <param name="VolumeName"></param> /// <param name="VolumeSerialNumber"></param> /// <param name="MaximumComponentLength"></param> /// <param name="FileSystemFlags"></param> /// <param name="FileSystemName"></param> /// <returns></returns> public static bool GetVolumeInformation( string RootPathName, out string VolumeName, out uint VolumeSerialNumber, out uint MaximumComponentLength, out FileSystemFeature FileSystemFlags, out string FileSystemName) { var volumeNameBuffer = new StringBuilder(1024, 1024); var fileSystemNameBuffer = new StringBuilder(1024, 1024); var result = NativeMethods.GetVolumeInformation(RootPathName, volumeNameBuffer, volumeNameBuffer.MaxCapacity, out VolumeSerialNumber, out MaximumComponentLength, out FileSystemFlags, fileSystemNameBuffer, fileSystemNameBuffer.Length); VolumeName = result ? volumeNameBuffer.ToString() : string.Empty; FileSystemName = result ? fileSystemNameBuffer.ToString() : string.Empty; return(result); }
public VolumeInformationTest(ITestOutputHelper outputHelper) { StringBuilder fileSystemNameBuffer = new StringBuilder(VolumeInformation.InteropStringCapacity); StringBuilder volumeNameBuffer = new StringBuilder(VolumeInformation.InteropStringCapacity); _rootDirectory = (new DirectoryInfo(Environment.SystemDirectory)).Root; if (!VolumeInformation.GetVolumeInformation(_rootDirectory.FullName, volumeNameBuffer, VolumeInformation.InteropStringCapacity, out uint volumeSerialNumber, out uint maximumComponentLength, out FileSystemFeature fileSystemFlags, fileSystemNameBuffer, VolumeInformation.InteropStringCapacity)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } _fileSystemFlags = fileSystemFlags; _isCaseSensitive = fileSystemFlags.HasFlag(FileSystemFeature.CaseSensitiveSearch); _volumeSerialNumber = volumeSerialNumber; _maximumComponentLength = maximumComponentLength; _fileSystemName = fileSystemNameBuffer.ToString(); _volumeName = volumeNameBuffer.ToString(); }
/// <summary> /// Initializes a new instance of <see cref="VolumeInformation"/>. /// </summary> /// <param name="directory">A child <seealso cref="DirectoryInfo"/> of the volume information to retrieve or null for the volume that contains the system directory.</param> public VolumeInformation(DirectoryInfo directory) { if (directory == null) { _root = new DirectoryInfo(Environment.SystemDirectory).Root; } StringBuilder volumeNameBuffer = new StringBuilder(InteropStringCapacity); StringBuilder fsn = new StringBuilder(InteropStringCapacity); if (!GetVolumeInformation(_root.FullName, volumeNameBuffer, InteropStringCapacity, out uint sn, out uint maxNameLength, out FileSystemFeature flags, fsn, InteropStringCapacity)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } VolumeName = volumeNameBuffer.ToString(); FileSystemName = fsn.ToString(); Flags = flags; SerialNumber = sn; MaxNameLength = maxNameLength; _nameComparer = (IsCaseSensitive) ? StringComparer.InvariantCulture : StringComparer.InvariantCultureIgnoreCase; }
private void lbl_help_Click(object sender, EventArgs e) { uint vol = 0, max = 0; FileSystemFeature f = new FileSystemFeature(); NativeMethod.GetVolumeInformation("C:", new StringBuilder(), 0, out vol, out max, out f, new StringBuilder(), 0); textBox1.Text = vol.ToString(); uint serialNum, serialNumLength; FileSystemFeature flags; StringBuilder volumename = new StringBuilder(256); StringBuilder fstype = new StringBuilder(256); bool ok = NativeMethod.GetVolumeInformation("C:\\", volumename, (uint)volumename.Capacity - 1, out serialNum, out serialNumLength, out flags, fstype, (uint)fstype.Capacity - 1); if (ok) { textBox1.Text = serialNum.ToString("X"); } var x = new System.IO.DriveInfo("C:\\ "); textBox2.Text = x.VolumeLabel; }
public static void GetVolumeInformationOfPath(string itemPath, out string rootPathName, out string volumeName, out uint volumeSerialNumber, out FileSystemFeature features, out string fileSystemName, out uint maxComponentLength) { // Determine root path name: var rootPathNameBuilder = new StringBuilder(2000); Kernel32.GetVolumePathName(itemPath, rootPathNameBuilder, rootPathNameBuilder.Capacity); rootPathName = rootPathNameBuilder.ToString(); // Get volumen information: StringBuilder volumeNameBuilder = new StringBuilder(261); StringBuilder fileSystemNameBuilder = new StringBuilder(261); if (!Kernel32.GetVolumeInformation(rootPathNameBuilder.ToString(), volumeNameBuilder, volumeNameBuilder.Capacity, out volumeSerialNumber, out maxComponentLength, out features, fileSystemNameBuilder, fileSystemNameBuilder.Capacity)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } volumeName = volumeNameBuilder.ToString(); fileSystemName = fileSystemNameBuilder.ToString(); }
public static extern Boolean GetVolumeInformation(String RootPathName, StringBuilder VolumeNameBuffer, Int32 VolumeNameSize, out UInt32 VolumeSerialNumber, out UInt32 MaximumComponentLength, out FileSystemFeature FileSystemFlags, StringBuilder FileSystemNameBuffer, Int32 nFileSystemNameSize);
private static extern bool GetVolumeInformationPrivate( string lpRootPathName, StringBuilder lpVolumeNameBuffer, int nVolumeNameSize, out uint lpVolumeSerialNumber, out uint lpMaximumComponentLength, out FileSystemFeature lpFileSystemFlags, StringBuilder lpFileSystemNameBuffer, int nFileSystemNameSize);
private static extern bool GetVolumeInformation( string rootPathName, StringBuilder volumeNameBuffer, int volumeNameSize, out uint volumeSerialNumber, out uint maximumComponentLength, out FileSystemFeature fileSystemFlags, StringBuilder fileSystemNameBuffer, int nFileSystemNameSize);