Я пытаюсь использовать пространство имен Windows.System
, входящее в состав WinRT, в PowerShell.Как ссылаться на компоненты WinRT в Powershell
Вместо dll
сборка поставляется как winmd
. Два способ загрузки сборок в PowerShell не похож на работу
#[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\Windows.winmd")
#Add-Type -Path "C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\Windows.winmd"
Я знаю, что с помощью Windows API является немного сложнее, чем загрузка моего кода .NET. У меня есть код pinched для использования частей win32, будет ли решение WinRT одинаковым?
$script:nativeMethods = @();
function Register-NativeMethod([string]$dll, [string]$methodSignature)
{
$script:nativeMethods += [PSCustomObject]@{ Dll = $dll; Signature = $methodSignature; }
}
function Add-NativeMethods()
{
$nativeMethodsCode = $script:nativeMethods | % { "
[DllImport(`"$($_.Dll)`")]
public static extern $($_.Signature);
" }
Add-Type @"
using System;
using System.Runtime.InteropServices;
public static class NativeMethods {
$nativeMethodsCode
}
"@
}
Register-NativeMethod "user32.dll" "int MessageBox (IntPtr hWnd, string text, string caption,int type)"
Add-NativeMethods
[NativeMethods]::MessageBox(0, "Please do not press this again.", "Attention", 0)| Out-Null
Моя цель - запустить Windows.System.Launcher.LaunchFileAsync("C:\file");
в PowerShell. Как я могу загрузить компоненты WinRT, которые мне нужны?