microsoft / Windows-IoT-Samples

This is the official repo for samples targeting Windows IoT
MIT License
57 stars 33 forks source link

Shell Launcher Script Issue #103

Open Sbasu2512 opened 3 months ago

Sbasu2512 commented 3 months ago

Hello,

I am attempting to use the powershell WMI bridge provider and the provided xml script.

I keep getting error:

Set-CimInstance : A general error occurred that is not covered by a more specific error code.
At C:\Users\SomashekarChandrappa\Downloads\acm-sw\acm-sw-installation-script-sayantan_acm-automation-scripts\automation
-scripts\shell_laucnher.ps1:47 char:9
+         Set-CimInstance -CimInstance $obj
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MDM_AssignedAcc..../Vendor/MSFT"):CimInstance) [Set-CimInstance], CimExce
   ption
    + FullyQualifiedErrorId : MI RESULT 1,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand

My code:

if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host "This script requires administrator privileges. Please run as administrator." -ForegroundColor Red
    exit $LASTEXITCODE
}

$assignedAccessConfiguration = @"
<?xml version="1.0" encoding="utf-8"?>
<ShellLauncherConfiguration xmlns="http://schemas.microsoft.com/embedded/2011/08/shelllauncher" 
xmlns:cmd="http://schemas.microsoft.com/embedded/2013/10/shelllauncher">
  <Profiles>
    <Profile Name="ACM Kiosk Profile" Description="ACM Software Kiosk Profile">
      <LaunchAction Type="DefaultApp">
        <App User="AutoLogonUser" Path="%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
             Args="-ExecutionPolicy Bypass -File %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\acm_start.lnk" />
        <App User="AutoLogonUser" Path="%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
             Args="--kiosk http://localhost:3000/ --edge-kiosk-type=fullscreen" />
        <App User="AutoLogonUser" Path="cmd.exe" Args="/c echo Breakout key sequence: Ctrl+A" />
      </LaunchAction>
    </Profile>
  </Profiles>
  <AutoLogonAccount DisplayName="ACM_SW" />
  <DefaultProfile Name="ACM Kiosk Profile" />
</ShellLauncherConfiguration>
"@

# Set the Assigned Access Configuration
$namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_AssignedAccess"

try {
    Write-Host "Getting the CIM instance."
    # Get the CIM instance
    $obj = Get-CimInstance -Namespace $namespaceName -ClassName $className

    if ($obj -ne $null) {
        Write-Host "CIM instance retrieved successfully."

        # Debug: Output the current configuration
        Write-Host "Current Configuration: $($obj.Configuration)"

        # Update the configuration
        $obj.Configuration = [System.Net.WebUtility]::HtmlEncode($assignedAccessConfiguration)

        # Apply the changes using Set-CimInstance
        Set-CimInstance -CimInstance $obj 
        Write-Output "CIM instance updated successfully."

    } else {
        Write-Host "No instance of class $className found."
    }
} catch {
    Write-Host "Error setting CIM instance: $_"
}

Windows specification: Edition Windows 11 Enterprise Version 23H2 Installed on ‎29-‎06-‎2024 OS build 22631.3737 Experience Windows Feature Experience Pack 1000.22700.1009.0

Can someone point me what is going wrong?

darknoidPL commented 3 months ago

Hello Sbasu2512, I am also straggling with this error, I've noticed that when you trying to implement "Shell Launcher" you should use $shellLauncherConfiguration = @" not $assignedAccessConfiguration = @". The same in # Update the configuration section: for ShellLauncher should use $obj.ShellLauncher = [System.Net.WebUtility]::HtmlEncode($shellLauncherConfiguration) not $obj.Configuration = [System.Net.WebUtility]::HtmlEncode($assignedAccessConfiguration). BTW - I did these two examples and in the end nothing works for me.

When I implemented:

<Configs>
    <Config>
        <AutoLogonAccount/>
        <Profile Id="{e7b80de1-ccdd-4478-876a-5fe8011cdbc7}"/>
    </Config>
</Configs>

It works, but only with local an account, I need domain an account... but when I change this part of code connected with Autologon then errors appear.

Do you have any suggestions?