0

我在安装过程中从 Windows 10 IoT Enterprise 下的桌面应用程序执行了两个 Powershell 脚本。

%WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -File ".\KeyboardFilter.ps1"
%WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -File ".\ShellLauncher.ps1"

但是 Powershell 脚本的执行并不成功。我收到以下错误:

Get-WMIObject : Provider load failure
At C:\Program Files\Application\KeyboardFilter.ps1:31 char:19
+ ... $predefined = Get-WMIObject -class WEKF_PredefinedKey @CommonParams |
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand


Write-Error : A positional parameter cannot be found that accepts argument 'is'.
At C:\Program Files\Application\KeyboardFilter.ps1:41 char:9
+         Write-Error $Id is not a valid predefined key
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Write-Error], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteErrorCommand


enable-windowsoptionalfeature : An attempt was made to load a program with an incorrect format.
At C:\Program Files\Application\ShellLauncher.ps1:4 char:1
+ enable-windowsoptionalfeature -online -featureName Client-EmbeddedShe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
    + FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand

安装过程从管理权限开始。第一个脚本将组合键添加到键盘过滤器(Windows 10 IoT 功能)。

第二个脚本启用并配置 Shell Launcher(也是 Windows 10 IoT 功能)。

键盘过滤器.ps1:

 param (
     [String] $ComputerName
 )

 $CommonParams = @{"namespace"="root\standardcimv2\embedded"}
 $CommonParams += $PSBoundParameters

 function Enable-Predefined-Key($Id) {   
     $predefined = Get-WMIObject -class WEKF_PredefinedKey @CommonParams |
         where {
             $_.Id -eq "$Id"
         };

     if ($predefined) {
         $predefined.Enabled = 1;
         $predefined.Put() | Out-Null;
         Write-Host Enabled $Id
     } else {
         Write-Error $Id is not a valid predefined key
     }
 }

如果我在批处理文件或 Powershell 控制台上执行 Powershell 脚本,一切正常。我还尝试在安装过程中使用 Powershell x86 和 x64 执行 Powershell 脚本,这两种情况下的错误都是相同的。

此问题的任何提示、提示或解决方案?

4

0 回答 0