microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23k stars 1.43k forks source link

winget configure with Registry resource unable to write to HKLM:\SOFTWARE\### from admin shell #3996

Open sperry opened 9 months ago

sperry commented 9 months ago

Brief description of your issue

Running from an administrator "cmd" prompt I am trying to use "winget configure" to apply the following:

properties:
  resources:
    - resource: Registry
      directives:
        description: add
      settings:
        Key: 'HKLM:\SOFTWARE\XYZ'
        Ensure: 'Present'
        ValueName: ''
        ValueType: 'String'
        ValueData: ''
        Force: 1
  configurationVersion: 0.2.0

I get

Apply :: Registry The configuration unit failed while attempting to apply the desired state. Exception calling "OpenSubKey" with "2" argument(s): "Requested registry access is not allowed."

It's only an issue creating Key directly under SOFTWARE. Again I am running from Administrator shell. Is Winget running as some other user

Steps to reproduce

Expected behavior

Registry key should be created as expected since I'm Administrator

Actual behavior

Registry key not created and error says "Requested registry access is not allowed"

Environment

Windows Package Manager (Preview) v1.7.2491-preview
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22621.2861
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.22.2491.0
denelon commented 9 months ago

I was testing on a newer version of WinGet, and I'm getting a different error.

properties:
  resources:
    - resource: PSDscResources/Registry
      directives:
        description: Add Key
      settings:
        Key: 'HKLM:\SOFTWARE\XYZ'
        Ensure: Present
        ValueName: MyValue
        ValueType: String
        ValueData: MyData
        Force: '$True'
  configurationVersion: 0.2.0
winget configure registry.dsc.yaml
Apply :: Registry
  Add Key
  Module: PSDscResources by Microsoft Corporation [Local]
    https://github.com/PowerShell/PSDscResources
    This module contains the standard DSC resources.
Because PSDscResources overwrites in-box resources, it is only available for WMF 5.1. Many of the resource updates provided here are also included in the xPSDesiredStateConfiguration module which is still compatible with WMF 4 and WMF 5 (though that module is not supported and may be removed in the future).

  Settings:
    Force: $True
    ValueName: MyValue
    Ensure: Present
    ValueData: MyData
    Key: HKLM:\SOFTWARE\XYZ
    ValueType: String
You are responsible for understanding the configuration settings you are choosing to execute. Microsoft is not responsible for the configuration file you have authored or imported. This configuration may change settings in Windows, install software, change software settings (including security settings), and accept user agreements to third-party packages and services on your behalf.  By running this configuration file, you acknowledge that you understand and agree to these resources and settings. Any applications installed are licensed to you by their owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages or services.
Have you reviewed the configuration and would you like to proceed applying it to the system?
[Y] Yes  [N] No: Y
Apply :: Registry
  The configuration unit failed while attempting to test the current system state.
Cannot process argument transformation on parameter 'Force'. Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.
<See the log file for additional details>
Some of the configuration was not applied successfully.