Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Failed to set a registry key with a path that contains spaces, slashes, and ends with a backslash #1068

Open
3 tasks done
Fredaker opened this issue Oct 28, 2024 · 0 comments
Assignees
Labels
Status: Needs Triage Needs to be labelled and assigned for review Type: Issue / Bug Something isn't working as expected

Comments

@Fredaker
Copy link

Prerequisites

PSAppDeployToolkit version

3.10.0+

Describe the bug

When I try to create a registry key with a path containing spaces, slashes, and ending with a backslash, like "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\", the Set-RegistryKey function creates the key as "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash" /f /reg:64.
On the second run, if the key already exists, the execution gets stuck. If a value needs to be set in that key, the function returns an error:

[Execution] [Set-RegistryKey] :: Failed to set value [value] for registry key [Registry::HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\] [name]. 
Error Record:
-------------
Message        : Cannot find path 'HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\' because it does not exist.

I encountered this behavior while parsing a .REG file, where the key is recorded as follows:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\]
"name"="value"

It’s not a major bug, but it still needs to be reported.

Steps to reproduce

There are no specific steps; just execute the following commands:

  1. # This sets a key with an unintended addition in the name: '" /f /reg:64' 
    # Resulting key name: "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash" /f /reg:64
    Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\"
  2. # Sets the key again with the unintended '" /f /reg:64' in the name
    # Resulting key name: "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash" /f /reg:64
    Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\"
    
    # Gets stuck on this second run
    Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\"
  3. # Sets the key with the unintended addition and throws an error:
    # "[Set-RegistryKey] :: Failed to set value [value] for registry key [Registry::HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\] [name].
    # Error Record: Message: Cannot find path 'HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\' because it does not exist."
    Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\name with space and /slash and end with backslash\" -Name 'name' -Value 'value' -Type String

Environment data

OsName               : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsProductName   : Windows 10 Enterprise
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}
KeyboardLayout       : en-US
TimeZone             : (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
HyperVisorPresent    : True
CsPartOfDomain       : False
CsPCSystemType       : Desktop
@coder-labeler coder-labeler bot added Status: Needs Triage Needs to be labelled and assigned for review Type: Issue / Bug Something isn't working as expected labels Oct 28, 2024
@mjr4077au mjr4077au self-assigned this Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Needs to be labelled and assigned for review Type: Issue / Bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants