gpt4 book ai didi

powershell - 从PowerShell调用Windows运行时类

转载 作者:行者123 更新时间:2023-12-04 18:11:07 25 4
gpt4 key购买 nike

有没有一种方法可以从PowerShell脚本中调用Windows运行时(WinRT)类(或对象)?我知道您可以调用COM对象,这些WinRT类应该被“公开”为...但是到目前为止,我的尝试都失败了...

这是我正在尝试的代码:

$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类”?

最佳答案

这似乎有些骇人听闻:

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完全有可能对其进行更改,因为它本质上是“隐藏的”且可能未完全开发的功能。

关于powershell - 从PowerShell调用Windows运行时类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14115415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com