从PowerShell调用Windows运行时类
发布时间:2020-12-14 04:37:35 所属栏目:Windows 来源:网络整理
导读:有没有办法从Power Shell脚本调用 Windows运行时(WinRT)类(或对象)?我知道你可以调用COM对象,WinRT类应该被“暴露”为……但到目前为止我的尝试都失败了…… 这是我正在尝试的代码: $lockscreen = New-Object -comObject Windows.System.UserProfile.LockS
有没有办法从Power
Shell脚本调用
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类”? 解决方法
这是一些似乎有用的hacky:
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,ContentType=WindowsRuntime. At line:1 char:1 + new-object "Windows.System.UserProfile.LockScreen,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:WindowsWebScreenimg100.png Authority : HostNameType : Basic IsDefaultPort : True IsFile : True IsLoopback : True PathAndQuery : C:/Windows/Web/Screen/img100.png ... 请注意,第一次调用失败,因为LockScreen没有构造函数,但该调用会在WinRT投影/元数据中执行某些操作,以便您现在可以调用LockScreen类上的静态方法/属性. 免责声明:我没有任何关于这种New-Object语法的文档,因此微软完全有可能改变它,因为它本质上是一个“隐藏的”,可能还没有完全开发的功能. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |