6

PowerShellスクリプトからWindowsランタイム(WinRT)クラス(またはオブジェクト)を呼び出す方法はありますか?WinRTクラスが「公開」されるはずのCOMオブジェクトを呼び出すことができることは知っていますが、これまでのところ、私の試みは失敗しています...

これは私が試している私のコードです:

$lockscreen = New-Object -comObject Windows.System.UserProfile.LockScreen

これにより、次のエラーが発生します。

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed
due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

WinRTクラスに使用する必要がある正しい「COMクラス」を知っている人はいますか?

4

2 に答える 2

6

これがうまくいくように見える何かハッキーです:

PS> new-object "Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,ContentType=WindowsRuntime"
new-object : Constructor not found. Cannot find an appropriate constructor for type
Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,ContentType=WindowsRuntime.
At line:1 char:1
+ new-object "Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,Con ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand

PS> [Windows.System.UserProfile.LockScreen]::OriginalImageFile


AbsolutePath   : C:/Windows/Web/Screen/img100.png
AbsoluteUri    : file:///C:/Windows/Web/Screen/img100.png
LocalPath      : C:\Windows\Web\Screen\img100.png
Authority      :
HostNameType   : Basic
IsDefaultPort  : True
IsFile         : True
IsLoopback     : True
PathAndQuery   : C:/Windows/Web/Screen/img100.png
...

LockScreenにはコンストラクターがないため、最初の呼び出しは失敗しますが、その呼び出しはWinRTプロジェクション/メタデータをプルするために何かを実行するため、LockScreenクラスの静的メソッド/プロパティを呼び出すことができます。

免責事項:このNew-Object構文について私が見つけることができるドキュメントはないので、それが本質的に「隠された」機能であり、おそらく完全には開発されていない機能であると考えて、Microsoftがそれを変更する可能性があります。

于 2013-01-03T07:21:24.640 に答える
5

タイプを参照するだけで、アセンブリを「ロード」できます。

[Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,ContentType=WindowsRuntime]
[Windows.System.UserProfile.LockScreen]::OriginalImageFile

PowerShellの結果でタイプが返されることを望まない場合は、

$null = [Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,ContentType=WindowsRuntime]
于 2013-11-06T20:24:07.723 に答える