2 # Windows Cab Package Provider - Microsoft 2016
3 # This resource manages the packages for a live image.
9 ConvertFrom-StringData @'
10 SourcePathDoesNotExist=Source does not exist: {0}
11 ConfigurationStarted=The configuration of WindowsPackageCab resource is starting
12 ConfigurationFinished=The configuration of WindowsPackageCab resource has completed
13 FailedToAddPackage=Failed to add package from {0}
14 FailedToRemovePackage=Failed to remove package {0}
15 SourcePathInvalid=Source path is null or empty
19 Import-LocalizedData LocalizedData -FileName WindowsPackageCab.Strings.psd1
22 class WindowsPackageCab {
24 # Property: Holds the product name of the package.
28 # Property: Makes sure a package is installed/not installed on the image.
29 [DscProperty(Mandatory)]
30 [ValidateSet("Absent","Present")]
33 # Property: Points to the location of a .cab file.
34 [DscProperty(Mandatory)]
37 # Property: Points the desired location for a log file
43 Import-DscNativeDISMMethods
48 Write-Verbose $script:LocalizedData.ConfigurationStarted
50 if ([string]::IsNullOrEmpty($this.SourcePath))
52 Throw-TerminatingError ($script:LocalizedData.SourcePathInvalid)
55 $SourcePathExists = Test-Path -Path $this.SourcePath
56 if (-not $SourcePathExists)
58 Throw-TerminatingError ($script:LocalizedData.SourcePathDoesNotExist -f $this.SourcePath)
61 if ($this.Ensure -match 'Present')
63 Add-CabPackage -PackagePath $this.SourcePath
67 Remove-CabPackage -PackagePath $this.SourcePath
70 Write-Verbose $script:LocalizedData.ConfigurationFinished
75 $details = Get-DISMDetailedInstalledPackageInfo -PackageName $this.Name
77 $isPackagePresent = Test-PackagePresence -packageInfoDetails $details
79 if ($this.Ensure -match 'Present')
81 return $isPackagePresent
85 return -not $isPackagePresent
89 [WindowsPackageCab] Get()
91 $details = Get-DISMDetailedInstalledPackageInfo -PackageName $this.Name
93 if ($details -eq $null)
95 $this.Ensure = 'Absent'
99 $this.Ensure = 'Present'
102 $this.SourcePath = $null
103 $this.LogPath = $null
109 Function Trace-Message
116 Write-Verbose $Message
120 New-Item -Path $this.LogPath -ErrorAction SilentlyContinue
121 Add-Content -Path $this.LogPath -Value $message
125 Function Throw-TerminatingError
130 [System.Management.Automation.ErrorRecord] $ErrorRecord,
131 [string] $ExceptionType
134 $exception = new-object "System.InvalidOperationException" $Message,$ErrorRecord.Exception
135 $errorRecord = New-Object System.Management.Automation.ErrorRecord $exception,"MachineStateIncorrect","InvalidOperation",$null
139 Function Test-PackagePresence
143 [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.DismDetailedPackageInfo] $packageInfoDetails
146 if (-not $packageInfoDetails)
151 if ($packageInfoDetails.PackageState -eq [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.DismPackageFeatureState]::DismStateInstalled -or
152 $packageInfoDetails.PackageState -eq [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.DismPackageFeatureState]::DismStateInstallPending)
160 Function Get-DISMDetailedInstalledPackageInfo
164 [string] $PackageName
169 $detailedPacketInfo = [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.Dism]::new().GetDetailedPackageInfo($PackageName, $this.LogPath)
173 $detailedPacketInfo = $null
176 return $detailedPacketInfo
179 Function Get-DISMDetailedCabFileInfo
183 [string] $PackagePath
186 return [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.Dism]::new().GetDetailedCabFileInfo($PackagePath, $this.LogPath)
189 Function Add-CabPackage
193 [string] $PackagePath
198 $dismStatus = [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.Dism]::new().AddPackage($PackagePath, $this.LogPath)
199 if ($dismStatus -eq [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.DismStatus]::DismStatusRebootRequired)
201 $global:DSCMachineStatus = 1;
203 Trace-Message ("-CabPackage successful. PackagePath = $PackagePath")
205 catch [System.Exception]
207 Throw-TerminatingError ($script:LocalizedData.FailedToAddPackage -f $this.SourcePath)
212 Function Remove-CabPackage
216 [string] $PackagePath
221 $dismStatus = [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.Dism]::new().RemovePackage($PackagePath, $this.LogPath)
222 if ($dismStatus -eq [Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.DismStatus]::DismStatusRebootRequired)
224 $global:DSCMachineStatus = 1;
226 Trace-Message ("Remove-CabPackage successful. PackagePath = $PackagePath")
228 catch [System.Exception]
230 Throw-TerminatingError ($script:LocalizedData.FailedToRemovePackage -f $this.SourcePath)
234 Function Import-DscNativeDISMMethods
236 if (-not ([System.Management.Automation.PSTypeName]'Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab.Dism').Type)
240 using System.Collections.Generic;
242 using System.Runtime.InteropServices;
245 using Environment = System.Management.Automation.Environment;
247 using Environment = System.Environment;
250 namespace Microsoft.PowerShell.DesiredStateConfiguration.WindowsPackageCab
252 #region Native Handlers
254 internal enum DismPackageIdentifier
261 internal enum DismLogLevel
264 DismLogErrorsWarnings,
265 DismLogErrorsWarningsInfo
268 [StructLayout(LayoutKind.Sequential, Pack = 1)]
269 internal class SystemTime
271 [MarshalAs(UnmanagedType.U2)]
273 [MarshalAs(UnmanagedType.U2)]
274 public UInt16 wMonth;
275 [MarshalAs(UnmanagedType.U2)]
276 public UInt16 wDayOfWeek;
277 [MarshalAs(UnmanagedType.U2)]
279 [MarshalAs(UnmanagedType.U2)]
281 [MarshalAs(UnmanagedType.U2)]
282 public UInt16 wMinute;
283 [MarshalAs(UnmanagedType.U2)]
284 public UInt16 wSecond;
285 [MarshalAs(UnmanagedType.U2)]
286 public UInt16 wMillisecond;
289 [StructLayout(LayoutKind.Sequential, Pack = 1)]
290 internal class DismPackage
292 [MarshalAs(UnmanagedType.LPWStr)]
293 internal string PackageName;
294 internal DismPackageFeatureState PackageState;
295 internal DismReleaseType ReleaseType;
296 internal SystemTime InstalledOn;
299 [StructLayout(LayoutKind.Sequential, Pack = 1)]
300 internal class DismPackageDetails
302 [MarshalAs(UnmanagedType.LPWStr)]
303 public string PackageName;
304 public DismPackageFeatureState PackageState;
305 public DismReleaseType ReleaseType;
306 public SystemTime InstalledOn;
307 public bool Applicable;
308 [MarshalAs(UnmanagedType.LPWStr)]
309 public string Copyright;
310 [MarshalAs(UnmanagedType.LPWStr)]
311 public string Company;
312 public SystemTime CreationTime;
313 [MarshalAs(UnmanagedType.LPWStr)]
314 public string DisplayName;
315 [MarshalAs(UnmanagedType.LPWStr)]
316 public string Description;
317 [MarshalAs(UnmanagedType.LPWStr)]
318 public string InstallClient;
319 [MarshalAs(UnmanagedType.LPWStr)]
320 public string InstallPackageName;
321 public SystemTime LastUpdateTime;
322 [MarshalAs(UnmanagedType.LPWStr)]
323 public string ProductName;
324 [MarshalAs(UnmanagedType.LPWStr)]
325 public string ProductVersion;
326 public DismRestartType RestartRequired;
327 public DismFullyOfflineInstallable FullyOffline;
328 [MarshalAs(UnmanagedType.LPWStr)]
329 public string SupportInformation;
330 public IntPtr CustomPropertyBuffer;
331 [MarshalAs(UnmanagedType.U4)]
332 public UInt32 CustomPropertyCount;
333 public IntPtr FeatureBuffer;
334 [MarshalAs(UnmanagedType.U4)]
335 public UInt32 FeatureCount;
338 [StructLayout(LayoutKind.Sequential, Pack = 1)]
339 internal class DismPackageCustomProperty
341 [MarshalAs(UnmanagedType.LPWStr)]
343 [MarshalAs(UnmanagedType.LPWStr)]
345 [MarshalAs(UnmanagedType.LPWStr)]
349 [StructLayout(LayoutKind.Sequential, Pack = 1)]
350 public class DismPackageFeature
352 [MarshalAs(UnmanagedType.LPWStr)]
353 public string FeatureName;
354 public DismPackageFeatureState State;
357 internal class DismNativeMethods
359 internal static string DismOnlineImage = "DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}";
361 [DllImport("DismApi.dll")]
362 public static extern int DismCloseSession(uint session);
364 [DllImport("DismApi.dll")]
365 public static extern int DismOpenSession(
366 [MarshalAs(UnmanagedType.LPWStr)] string imagePath,
367 [MarshalAs(UnmanagedType.LPWStr)] string windowsDirectory,
368 [MarshalAs(UnmanagedType.LPWStr)] string systemDrive,
372 [DllImport("DismApi.dll")]
373 public static extern int DismInitialize(
374 DismLogLevel logLevel,
375 [MarshalAs(UnmanagedType.LPWStr)] string logFilePath,
376 [MarshalAs(UnmanagedType.LPWStr)] string scratchDirectory
379 [DllImport("DismApi.dll")]
380 public static extern int DismShutdown();
382 [DllImport("DismApi.dll")]
383 public static extern int DismDelete(IntPtr dismStructure);
385 [DllImport("DismApi.dll")]
386 public static extern int DismGetPackages(
388 out IntPtr packageBufPtr,
389 out uint packageCount
392 [DllImport("DismApi.dll")]
393 public static extern int DismGetPackageInfo(
395 [MarshalAs(UnmanagedType.LPWStr)] string identifier,
396 DismPackageIdentifier packageIdentifier,
397 out IntPtr packageInfo
400 [DllImport("DismApi.dll")]
401 public static extern int DismAddPackage(
403 [MarshalAs(UnmanagedType.LPWStr)] string packagePath,
404 [MarshalAs(UnmanagedType.Bool)] bool ignoreCheck,
405 [MarshalAs(UnmanagedType.Bool)] bool preventPending,
407 DismProgressCallback progress,
411 [DllImport("DismApi.dll")]
412 public static extern int DismRemovePackage(
414 [MarshalAs(UnmanagedType.LPWStr)] string identifier,
415 DismPackageIdentifier packageIdentifier,
417 DismProgressCallback progress,
421 public delegate void DismProgressCallback(
427 internal static DateTime GetDateTimeFromSystemTime(SystemTime time)
431 return new DateTime(time.wYear, time.wMonth, time.wDay,
432 time.wHour, time.wMinute, time.wSecond, DateTimeKind.Local);
434 catch (ArgumentOutOfRangeException)
436 return new DateTime(0, DateTimeKind.Local);
441 #endregion Native Handlers
443 #region Helper Classes
445 internal class DismHandler : IDisposable
447 #region Private Members
449 private readonly string _logPath;
450 private uint _sessionToken;
451 private readonly DismLogLevel _logLevel;
452 private bool _sessionOpened;
454 #endregion Private Members
457 internal DismHandler(string logPath, DismLogLevel logLevel)
460 _logLevel = logLevel;
463 internal DismHandler() : this(string.Format("{0}\\dism.log", Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System))), DismLogLevel.DismLogErrorsWarnings) { }
465 internal DismHandler(string logPath)
467 if (!String.IsNullOrEmpty(logPath))
470 _logPath = string.Format("{0}\\dism.log", Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)));
472 _logLevel = DismLogLevel.DismLogErrorsWarnings;
474 #endregion Constructors
476 #region Private Methods
477 private const int CbsInvalidPackage = unchecked((int)0x800f0805);
478 private const int FileNotFound = unchecked((int)0x80070002);
479 private const int CorruptedFile = unchecked((int)0x80070570);
480 private const int InvalidArgument = unchecked((int)0x80070057);
481 private const int SessionReloadRequired = 0x1;
482 private const int MachineRebootRequired = 0xbc2;
484 private static void ValidateResult(int hr)
487 if (IsSpecialErrorCode(hr)) return;
491 case CbsInvalidPackage: // 0x800f0805
493 // 0x800f0805 -2146498555 : CBS_E_INVALID_PACKAGE the update package was not a valid CSI update
494 // when package is queried by name and is not installed
495 throw new DismInvalidPackageException(string.Format("Dism error code = {0}", hr));
497 case FileNotFound: // 0x80070002
499 // 0x80070002 : -2147024894 E_FILE_NOT_FOUND The system cannot find the file specified.
500 // when package is queried by path and the file does not exist
501 throw new FileNotFoundException();
503 case CorruptedFile: // 0x80070570
505 // 0x80070570 : 1392 ERROR_FILE_CORRUPT The file or directory is corrupted and unreadable
506 // when package file iscorrupted and unreadable
507 throw new DismInvalidPackageException(string.Format("Dism error code = {0}", hr));
509 case InvalidArgument: // 0x80070057
511 // 0x80070057 -2147024809 : E_INVALIDARG One or more arguments are invalid
512 // when package is queried by name and is not installed
513 throw new DismInvalidPackageException(string.Format("Dism error code = {0}", hr));
517 throw new DismException(string.Format("Dism error code = {0}", hr));
523 /// Special Error codes are not failures. They are positive values and often indicate an expected followup operation.
525 /// <param name="errorCode"></param>
526 /// <returns></returns>
527 private static bool IsSpecialErrorCode(int errorCode)
531 case SessionReloadRequired:
535 case MachineRebootRequired:
544 private static DismStatus GetStatusFromErrorCode(int errorCode)
548 case SessionReloadRequired:
550 return DismStatus.DismStatusSuccess;
552 case MachineRebootRequired:
554 return DismStatus.DismStatusRebootRequired;
558 return DismStatus.DismStatusSuccess;
561 private void OpenSession()
563 if (_sessionOpened) return;
565 var hr = DismNativeMethods.DismInitialize(_logLevel, _logPath, null);
568 hr = DismNativeMethods.DismOpenSession(DismNativeMethods.DismOnlineImage, null, null, out _sessionToken);
571 _sessionOpened = true;
574 private void CloseSession()
576 if (!_sessionOpened) return;
578 var hr = DismNativeMethods.DismCloseSession(_sessionToken);
581 DismNativeMethods.DismShutdown();
583 _sessionOpened = false;
586 private void DeleteDismBuffer(IntPtr buffer)
588 if (buffer != IntPtr.Zero) DismNativeMethods.DismDelete(buffer);
589 buffer = IntPtr.Zero;
592 #endregion Private Methods
596 public void Dispose()
599 GC.SuppressFinalize(this);
602 protected void Dispose(bool isDisposing)
611 internal List<DismPackageInfo> GetInstalledPackages()
615 List<DismPackageInfo> packages = new List<DismPackageInfo>();
617 IntPtr pPackagesBuffer;
618 uint numOfPackages = 0;
620 var hr = DismNativeMethods.DismGetPackages(_sessionToken, out pPackagesBuffer, out numOfPackages);
625 var pBuffer = pPackagesBuffer;
626 var originalPackageSize = Marshal.SizeOf(typeof(DismPackage));
627 for (uint i = 0; i < numOfPackages; i++)
631 var dismPackage = (DismPackage)Marshal.PtrToStructure(pBuffer, typeof(DismPackage));
632 if (dismPackage != null)
634 packages.Add(new DismPackageInfo(dismPackage));
639 pBuffer = new IntPtr(pBuffer.ToInt64() + originalPackageSize);
645 if (pPackagesBuffer != IntPtr.Zero)
647 DismNativeMethods.DismDelete(pPackagesBuffer);
653 internal DismDetailedPackageInfo GetPackageInfo(string identifier, DismPackageIdentifier packageIdentifier)
661 hr = DismNativeMethods.DismGetPackageInfo(_sessionToken, identifier, packageIdentifier, out packageInfo);
666 var details = (DismPackageDetails)Marshal.PtrToStructure(packageInfo, typeof(DismPackageDetails));
667 return extractDismDetailedPackageInfo(details);
671 DeleteDismBuffer(packageInfo);
675 internal DismDetailedPackageInfo extractDismDetailedPackageInfo(DismPackageDetails details)
677 string PackageName = details.PackageName;
678 DismPackageFeatureState PackageState = details.PackageState;
679 DismReleaseType ReleaseType = details.ReleaseType;
680 DateTime InstalledOn = DismNativeMethods.GetDateTimeFromSystemTime(details.InstalledOn);
681 bool Applicable = details.Applicable;
682 string Copyright = details.Copyright;
683 string Company = details.Company;
684 DateTime CreationTime = DismNativeMethods.GetDateTimeFromSystemTime(details.CreationTime);
685 string DisplayName = details.DisplayName;
686 string Description = details.Description;
687 string InstallClient = details.InstallClient;
688 string InstallPackageName = details.InstallPackageName;
689 DateTime LastUpdateTime = DismNativeMethods.GetDateTimeFromSystemTime(details.LastUpdateTime);
690 string ProductName = details.ProductName;
691 string ProductVersion = details.ProductVersion;
692 DismRestartType RestartRequired = details.RestartRequired;
693 DismFullyOfflineInstallable FullyOffline = details.FullyOffline;
694 string SupportInformation = details.SupportInformation;
696 List<DismCustomProperty> CustomProperty = new List<DismCustomProperty>();
698 IntPtr currentCustomPropertyPtr = details.CustomPropertyBuffer;
699 for (int i = 0; i < details.CustomPropertyCount; ++i)
701 DismCustomProperty customPropertyInstance = new DismCustomProperty(currentCustomPropertyPtr);
702 CustomProperty.Add(customPropertyInstance);
703 currentCustomPropertyPtr = new IntPtr(currentCustomPropertyPtr.ToInt64() + Marshal.SizeOf(typeof(DismCustomProperty)));
706 List<DismFeature> Feature = new List<DismFeature>();
707 IntPtr currentFeaturePtr = details.FeatureBuffer;
708 for (int i = 0; i < details.FeatureCount; ++i)
710 DismFeature basicFeature = new DismFeature(currentFeaturePtr);
711 Feature.Add(basicFeature);
712 currentFeaturePtr = new IntPtr(currentFeaturePtr.ToInt64() + Marshal.SizeOf(typeof(DismPackageFeature)));
715 return new DismDetailedPackageInfo(
739 internal DismStatus AddPackage(string packagePath)
744 var hr = DismNativeMethods.DismAddPackage(_sessionToken, packagePath, false, false, IntPtr.Zero, null, IntPtr.Zero);
746 return GetStatusFromErrorCode(hr);
749 internal DismStatus RemoveInstalledPackage(string packagePath)
753 // Remove the package
754 var hr = DismNativeMethods.DismRemovePackage(_sessionToken, packagePath, DismPackageIdentifier.DismPackagePath, IntPtr.Zero, null, IntPtr.Zero);
756 return GetStatusFromErrorCode(hr);
759 #endregion Core Logic
762 #endregion Helper Classes
766 public class DismException : Exception
768 public DismException(string message) : base(message)
773 public class DismInvalidPackageException : Exception
775 public DismInvalidPackageException(string message)
780 public class DismSessionException : Exception
782 public DismSessionException(string message)
788 /// Core Dism class is used directly by the resource and provides a managed interface
793 /// Get a list of installed packages
795 /// <returns>list containining installed packages</returns>
796 public List<DismPackageInfo> GetInstalledPackages(string logPath = null)
798 using (var dismHandler = new DismHandler(logPath))
800 return dismHandler.GetInstalledPackages();
805 /// Get detailed package info based on unique package name
807 /// <param name="packageName"></param>
808 /// <returns></returns>
809 public DismDetailedPackageInfo GetDetailedPackageInfo(string packageName, string logPath = null)
811 using (var dismHandler = new DismHandler(logPath))
813 return dismHandler.GetPackageInfo(packageName, DismPackageIdentifier.DismPackageName);
818 /// Get detailed package info based on path to a .cab file
820 public DismDetailedPackageInfo GetDetailedCabFileInfo(string packagePath, string logPath = null)
822 using (var dismHandler = new DismHandler(logPath))
824 return dismHandler.GetPackageInfo(packagePath, DismPackageIdentifier.DismPackagePath);
829 /// Install windows package from .cab file
831 /// <param name="packagePath"></param>
832 /// <returns></returns>
833 public DismStatus AddPackage(string packagePath, string logPath = null)
835 using (var dismHandler = new DismHandler(logPath))
837 return dismHandler.AddPackage(packagePath);
842 /// Remove the installed windows package pointed to by the .cab file
844 /// <param name="packagePath"></param>
845 /// <returns></returns>
846 public DismStatus RemovePackage(string packagePath, string logPath = null)
848 using (var dismHandler = new DismHandler(logPath))
850 return dismHandler.RemoveInstalledPackage(packagePath);
854 private static readonly object SyncObject = new object();
855 private static Dism _instance;
856 public static Dism Instance
860 if (_instance == null)
864 if (_instance == null)
866 _instance = new Dism();
876 public class DismDetailedPackageInfo
878 public string PackageName;
879 public DismPackageFeatureState PackageState;
880 public DismReleaseType ReleaseType;
881 public DateTime InstalledOn;
882 public bool Applicable;
883 public string Copyright;
884 public string Company;
885 public DateTime CreationTime;
886 public string DisplayName;
887 public string Description;
888 public string InstallClient;
889 public string InstallPackageName;
890 public DateTime LastUpdateTime;
891 public string ProductName;
892 public string ProductVersion;
893 public DismRestartType RestartRequired;
894 public DismFullyOfflineInstallable FullyOffline;
895 public string SupportInformation;
896 public List<DismCustomProperty> CustomProperty;
897 public List<DismFeature> Feature;
899 internal DismDetailedPackageInfo(
901 DismPackageFeatureState aPackageState,
902 DismReleaseType aReleaseType,
903 DateTime aInstalledOn,
907 DateTime aCreationTime,
910 string aInstallClient,
911 string aInstallPackageName,
912 DateTime aLastUpdateTime,
914 string aProductVersion,
915 DismRestartType aRestartRequired,
916 DismFullyOfflineInstallable aFullyOffline,
917 string aSupportInformation,
918 List<DismCustomProperty> aCustomProperty,
919 List<DismFeature> aFeature
922 PackageName = aPackageName;
923 PackageState = aPackageState;
924 ReleaseType = aReleaseType;
925 InstalledOn = aInstalledOn;
926 Applicable = aApplicable;
927 Copyright = aCopyright;
929 CreationTime = aCreationTime;
930 DisplayName = aDisplayName;
931 Description = aDescription;
932 InstallClient = aInstallClient;
933 InstallPackageName = aInstallPackageName;
934 LastUpdateTime = aLastUpdateTime;
935 ProductName = aProductName;
936 ProductVersion = aProductVersion;
937 RestartRequired = aRestartRequired;
938 FullyOffline = aFullyOffline;
939 SupportInformation = aSupportInformation;
940 CustomProperty = aCustomProperty;
945 public class DismCustomProperty
951 public DismCustomProperty(
962 public DismCustomProperty(IntPtr DismPackageCustomPropertyPtr)
964 DismPackageCustomProperty customProperty = (DismPackageCustomProperty)Marshal.PtrToStructure(DismPackageCustomPropertyPtr, typeof(DismPackageCustomProperty));
966 Name = customProperty.Name;
967 Value = customProperty.Value;
968 Path = customProperty.Path;
972 public class DismFeature
974 public string FeatureName;
975 public DismFeatureState FeatureState;
977 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
978 public DismFeature(IntPtr FeatureBuf)
980 DismPackageFeature Feature = (DismPackageFeature)Marshal.PtrToStructure(FeatureBuf, typeof(DismPackageFeature));
982 SetFeatureState(Feature.State);
983 FeatureName = Feature.FeatureName;
986 public void SetFeatureState(DismPackageFeatureState state)
990 case DismPackageFeatureState.DismStateNotPresent:
991 case DismPackageFeatureState.DismStateStaged:
992 FeatureState = DismFeatureState.Disabled;
994 case DismPackageFeatureState.DismStateUninstallPending:
995 FeatureState = DismFeatureState.DisablePending;
997 case DismPackageFeatureState.DismStateResolved:
998 FeatureState = DismFeatureState.DisabledWithPayloadRemoved;
1000 case DismPackageFeatureState.DismStateInstalled:
1001 FeatureState = DismFeatureState.Enabled;
1003 case DismPackageFeatureState.DismStateInstallPending:
1004 FeatureState = DismFeatureState.EnablePending;
1006 case DismPackageFeatureState.DismStateSuperseded:
1007 FeatureState = DismFeatureState.Superseded;
1009 case DismPackageFeatureState.DismStatePartiallyInstalled:
1010 FeatureState = DismFeatureState.PartiallyInstalled;
1013 FeatureState = DismFeatureState.Disabled;
1019 public enum DismPackageFeatureState
1021 DismStateNotPresent = 0,
1022 DismStateUninstallPending,
1025 DismStateRemoved = DismStateResolved,
1027 DismStateInstallPending,
1028 DismStateSuperseded,
1029 DismStatePartiallyInstalled
1032 public enum DismFeatureState
1040 DisabledWithPayloadRemoved
1043 public enum DismReleaseType
1045 DismReleaseTypeCriticalUpdate = 0,
1046 DismReleaseTypeDriver,
1047 DismReleaseTypeFeaturePack,
1048 DismReleaseTypeHotfix,
1049 DismReleaseTypeSecurityUpdate,
1050 DismReleaseTypeSoftwareUpdate,
1051 DismReleaseTypeUpdate,
1052 DismReleaseTypeUpdateRollup,
1053 DismReleaseTypeLanguagePack,
1054 DismReleaseTypeFoundation,
1055 DismReleaseTypeServicePack,
1056 DismReleaseTypeProduct,
1057 DismReleaseTypeLocalPack,
1058 DismReleaseTypeOther
1061 public class DismPackageInfo
1064 public DismPackageFeatureState PackageState;
1065 public DismReleaseType ReleaseType;
1066 public DateTime InstalledOn;
1068 internal DismPackageInfo(DismPackage package)
1070 Name = package.PackageName;
1071 PackageState = package.PackageState;
1072 ReleaseType = package.ReleaseType;
1073 InstalledOn = DismNativeMethods.GetDateTimeFromSystemTime(package.InstalledOn);
1077 public enum DismRestartType
1080 DismRestartPossible = 1,
1081 DismRestartRequired = 2
1084 public enum DismFullyOfflineInstallable
1086 DismFullyOfflineInstallable = 0,
1087 DismFullyOfflineNotInstallable = 1,
1088 DismFullyOfflineInstallableUndetermined = 2
1091 public enum DismStatus
1093 DismStatusSuccess = 0,
1094 DismStatusRebootRequired = 1,
1095 DismStatusFailed = 2
1098 #endregion Core logic
1105 Add-Type -TypeDefinition $source
1109 Export-ModuleMember -Function ''