Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $path = "D:\TEST"
- $signature = @'
- [DllImport("msi.dll", CharSet=CharSet.Unicode)]
- public static extern unsafe int MsiGetProperty(
- int hInstall,
- string szName,
- [Out] StringBuilder szValueBuf,
- ref int pchValueBuf);
- [DllImport("msi.dll", CharSet = CharSet.Unicode, PreserveSig = true, SetLastError = true, ExactSpelling = true)]
- public static extern unsafe UInt32 MsiOpenPackageEx(
- string szPackagePath,
- UInt32 dwOptions,
- [Out] void **hProduct);
- '@
- $unsafe = New-Object System.CodeDom.Compiler.CompilerParameters
- $unsafe.CompilerOptions="/unsafe"
- [int] $code
- [IntPtr]$ptr = [IntPtr]::zero
- [string] $property = "ProductCode"
- $output = New-Object System.Text.StringBuilder(512);
- Add-Type -MemberDefinition $signature -Name ProductCodeCustom -Namespace CustomScript -PassThru -Using System.Text -CompilerParameters $unsafe
- [CustomScript.ProductCodeCustom]::MsiOpenPackageEx($path, 1, [ref] $ptr)
- [CustomScript.ProductCodeCustom]::MsiGetProperty([ref] $code, $property, $null, $output.MaxCapacity)
- $output.ToString()
- ////////////////ERRRRRRRRRRORRRRRRRRRRR CCCCCOOOOOOODDDDDDDEEEEEEESSSS//////////////////////
- Exception calling "MsiOpenPackageEx" with "3" argument(s): "Operation could destabilize the runtime."
- + [CustomScript.ProductCodeCustom]::MsiOpenPackageEx($path, 1, [ref] $p ...
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- + FullyQualifiedErrorId : VerificationException
- [ref] cannot be applied to a variable that does not exist.
- + [CustomScript.ProductCodeCustom]::MsiGetProperty([ref] $code, $proper ...
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : InvalidOperation: (code:VariablePath) [], RuntimeException
- + FullyQualifiedErrorId : NonExistingVariableReference
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement