You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 7 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #region Internals
  2. #region C# Code
  3. $type_NTFS1 = @'
  4. using System;
  5. using System.IO;
  6. using System.Collections;
  7. using System.Runtime.InteropServices;
  8. using Microsoft.Win32.SafeHandles;
  9. namespace NTFS
  10. {
  11. public class DriveInfoExt
  12. {
  13. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  14. static extern bool GetDiskFreeSpace(string lpRootPathName,
  15. out uint lpSectorsPerCluster,
  16. out uint lpBytesPerSector,
  17. out uint lpNumberOfFreeClusters,
  18. out uint lpTotalNumberOfClusters);
  19. DriveInfo _drive = null;
  20. uint _sectorsPerCluster = 0;
  21. uint _bytesPerSector = 0;
  22. uint _numberOfFreeClusters = 0;
  23. uint _totalNumberOfClusters = 0;
  24. public uint SectorsPerCluster { get { return _sectorsPerCluster; } }
  25. public uint BytesPerSector { get { return _bytesPerSector; } }
  26. public uint NumberOfFreeClusters { get { return _numberOfFreeClusters; } }
  27. public uint TotalNumberOfClusters { get { return _totalNumberOfClusters; } }
  28. public DriveInfo Drive { get { return _drive; } }
  29. public string DriveName { get { return _drive.Name; } }
  30. public string VolumeName { get { return _drive.VolumeLabel; } }
  31. public DriveInfoExt(string DriveName)
  32. {
  33. _drive = new DriveInfo(DriveName);
  34. GetDiskFreeSpace(_drive.Name,
  35. out _sectorsPerCluster,
  36. out _bytesPerSector,
  37. out _numberOfFreeClusters,
  38. out _totalNumberOfClusters);
  39. }
  40. }
  41. public class FileInfoExt
  42. {
  43. [DllImport("kernel32.dll", SetLastError = true, EntryPoint = "GetCompressedFileSize")]
  44. static extern uint GetCompressedFileSize(string lpFileName, out uint lpFileSizeHigh);
  45. public static ulong GetCompressedFileSize(string filename)
  46. {
  47. uint high;
  48. uint low;
  49. low = GetCompressedFileSize(filename, out high);
  50. int error = Marshal.GetLastWin32Error();
  51. if (high == 0 && low == 0xFFFFFFFF && error != 0)
  52. {
  53. throw new System.ComponentModel.Win32Exception(error);
  54. }
  55. else
  56. {
  57. return ((ulong)high << 32) + low;
  58. }
  59. }
  60. }
  61. }
  62. '@
  63. #endregion
  64. #endregion
  65. Add-Type -TypeDefinition $type_NTFS1
  66. Add-Type -Path $PSScriptRoot\Security2.dll
  67. Add-Type -Path $PSScriptRoot\PrivilegeControl.dll -ReferencedAssemblies $PSScriptRoot\ProcessPrivileges.dll
  68. Add-Type -Path $PSScriptRoot\ProcessPrivileges.dll
  69. #using Update-FormatData and not FormatsToProcess in the PSD1 as FormatsToProcess does not offer
  70. #putting format data in front of the default data. This is required to make the new formatter the default ones.
  71. Update-FormatData -PrependPath $PSScriptRoot\NTFSSecurity.format.ps1xml