Advertisement
Guest User

Powershell types

a guest
Sep 19th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $path = "D:\TEST"
  2.  
  3. $signature = @'
  4. [DllImport("msi.dll", CharSet=CharSet.Unicode)]
  5. public static extern unsafe int MsiGetProperty(
  6.    int hInstall,
  7.    string szName,
  8.   [Out] StringBuilder szValueBuf,
  9.   ref int pchValueBuf);
  10.  
  11. [DllImport("msi.dll", CharSet = CharSet.Unicode, PreserveSig = true, SetLastError = true, ExactSpelling = true)]
  12. public static extern unsafe UInt32 MsiOpenPackageEx(
  13.     string szPackagePath,
  14.     UInt32 dwOptions,
  15.     [Out] void **hProduct);
  16. '@
  17. $unsafe = New-Object System.CodeDom.Compiler.CompilerParameters
  18. $unsafe.CompilerOptions="/unsafe"
  19.  
  20. [int] $code
  21. [IntPtr]$ptr = [IntPtr]::zero
  22. [string] $property = "ProductCode"
  23.  
  24. $output = New-Object System.Text.StringBuilder(512);
  25.  
  26. Add-Type -MemberDefinition $signature -Name ProductCodeCustom -Namespace CustomScript -PassThru -Using System.Text -CompilerParameters $unsafe
  27. [CustomScript.ProductCodeCustom]::MsiOpenPackageEx($path, 1, [ref] $ptr)
  28. [CustomScript.ProductCodeCustom]::MsiGetProperty([ref] $code, $property, $null, $output.MaxCapacity)
  29.  
  30. $output.ToString()
  31.  
  32. ////////////////ERRRRRRRRRRORRRRRRRRRRR CCCCCOOOOOOODDDDDDDEEEEEEESSSS//////////////////////
  33.  
  34. Exception calling "MsiOpenPackageEx" with "3" argument(s): "Operation could destabilize the runtime."
  35. + [CustomScript.ProductCodeCustom]::MsiOpenPackageEx($path, 1, [ref] $p ...
  36. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37.     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  38.     + FullyQualifiedErrorId : VerificationException
  39.  
  40. [ref] cannot be applied to a variable that does not exist.
  41. + [CustomScript.ProductCodeCustom]::MsiGetProperty([ref] $code, $proper ...
  42. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43.     + CategoryInfo          : InvalidOperation: (code:VariablePath) [], RuntimeException
  44.     + FullyQualifiedErrorId : NonExistingVariableReference
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement