Windows 如何在Powershell中引用WinRT组件
我试图在PowerShell中使用名称空间,WinRT的一部分 程序集不是Windows 如何在Powershell中引用WinRT组件,windows,powershell,windows-8,windows-runtime,Windows,Powershell,Windows 8,Windows Runtime,我试图在PowerShell中使用名称空间,WinRT的一部分 程序集不是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
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代码要复杂一些。我有使用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组件?要将WinRT二进制文件加载到PowerShell中,请使用以下示例:
> [Windows.Data.Json.JsonValue,Windows.Web,ContentType=WindowsRuntime]
> $value = new-object Windows.Data.Json.JsonObject
> $value.Stringify()
{}
我想您需要一个存储文件
:
> [Windows.System.Launcher,Windows.Web,ContentType=WindowsRuntime]
> [Windows.System.Launcher]::LaunchFileAsync
OverloadDefinitions
-------------------
static Windows.Foundation.IAsyncOperation[bool] LaunchFileAsync(Windows.Storage.IStorageFile file)
static Windows.Foundation.IAsyncOperation[bool] LaunchFileAsync(Windows.Storage.IStorageFile file, Windows.System.LauncherOptions options)
要创建一个,可以执行以下操作:
> [Windows.Management.Core.ApplicationDataManager,Windows.Web,ContentType=WindowsRuntime]
> $value = [Windows.Management.Core.ApplicationDataManager]::CreateForPackageFamily("BackgroundTaskApp_mxmz85hp10cp4")
> $asyncInfo = $value.LocalFolder.CreateFileAsync("foo.txt")
要使用wait*Async()
方法,您需要执行类似于To的操作。我认为这不起作用。