can't access hkcu

Welcome Forums General PowerShell Q&A can't access hkcu

This topic contains 5 replies, has 3 voices, and was last updated by

4 years, 4 months ago.

  • Author
  • #19321

    Points: 1
    Rank: Member

    I have PS v4 and am working in Windows 8.1. I have been working in PS ISE as an administrator.

    I was doing the chapter 5 lab exercise in "Learning Windows Powershell 3 in a month of lunches" (resetting the property value of Dontprettypath using '>set-itemproperty -path advanced -PSPropert Enabledontprettypath -value 1'). For some reason, it was not working.

    While checking for what I might have done wrong, I think that I reset the value for HKCU. I was prompted for a value and I typed in 'cls'.

    When I run 'get-psdrive', I see hkcu listed.

    However, I checking the location gives the following message:
    >set-location -path hkcu
    set-location : Cannot find path 'C:hkcu' because it does not exist.
    At line:1, char :1
    +set-location -path hkcu
    + CategoryInfo : ObjectNotFound: (C:\hkcu:String) [Set-Location], ItemNotFoundException
    +FullyQualifiedErrorId : PathNotFound,MicrosoftPowerShell.Commands.SetLocationCommand

    I would appreciate any help you can give.


  • #19322

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Drive names are followed by a colon.

    Cd HKCU:

  • #19347

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    as a longer explanation for folks who may come across this...

    The reason drive names must always be followed by a colon, when the drive name is being used as part of a path, is so that the shell can tell the difference between a drive and a folder.

    cd drive

    Would try to change to a folder named "drive."

    cd drive:

    Changes to a drive named "drive." The colon is what lets the shell figure out what you're trying to do.

  • #19425

    Points: 1
    Rank: Member

    Thanks. That worked.

    Is 'set-location -path HKCU' not a valid method of moving to HKCU?

  • #19427

    Points: 24
    Team Member
    Rank: Member

    Set-Location is a valid method but you need add a colon to change into the drive.

    PS C:\> Set-Location -Path HKCU:
    PS HKCU:\>

    "cd" is just an alias for Set-Location. Every time you use "cd" the PowerShell engine will invoke Set-Location with the Path parameter.

    PS C:\> Get-Alias -Name cd
    CommandType     Name
    Alias           cd -> Set-Location

    Aliases are great for the interactive usage of the PowerShell console because it means less typing. It is very important to get know the aliases because once you get into creating scripts than other PowerShell users except not to see any aliases in your scripts.

  • #19491

    Points: 1
    Rank: Member

    Thanks again!

The topic ‘can't access hkcu’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort