0

I execute two Powershell scripts during a installation process from a desktop application under Windows 10 IoT Enterprise.

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

But the execution of the Powershell scripts is not successful. I get the following errors:

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

The installation process starts with administration permissions. The first script adds key combinations to the Keyboard Filter (Windows 10 IoT feature).

The second scripts enable and configure the Shell Launcher (also Windows 10 IoT feature).

KeyboardFilter.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
     }
 }

If I execute the Powershell scripts in a batchfile or on Powershell console, everything works fine. I also tried to execute the Powershell scripts during the installation process with Powershell x86 and x64, same errors in both cases.

Any hints, tips or solution for this problem?

Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
Niklas
  • 27
  • 7
  • The first error sounds like the class does not exist. The second error is a straight syntax error. You need quotes around the string you are trying to write. – EBGreen Mar 16 '18 at 14:11
  • @EBGreen, first error: I verified, the class exists in the corresponding namespace. If I execute the Powershell scripts on the commandline (not during the installtion process) everything works fine. Second error: Yes, it was a syntax error. – Niklas Mar 19 '18 at 07:28
  • So it sounds like the install itself might be mucking about with that class. Perhaps try changing the timing on when you try to do this bit in relation to when the install actually happens. – EBGreen Mar 19 '18 at 14:07
  • @EBGreen, I had the same idea. Currently the installation process does nothing beside execute the powershell scripts and I still get the same errors... Maybay I should search for another way to configure the Win10 IoT features and stop "trying" with Power Shell. – Niklas Mar 19 '18 at 15:18
  • Might be something that you can do through dism. – EBGreen Mar 19 '18 at 15:26

0 Answers0