can't access hkcu

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Eric Palmer Eric Palmer 2 years, 1 month ago.

  • Author
    Posts
  • #19321
    Profile photo of Eric Palmer
    Eric Palmer
    Participant

    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.

    Thanks

  • #19322
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Drive names are followed by a colon.

    Cd HKCU:

  • #19347
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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 [i]folder[/i] named "drive."

    cd drive:

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

  • #19425
    Profile photo of Eric Palmer
    Eric Palmer
    Participant

    Thanks. That worked.

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

  • #19427
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
    Profile photo of Eric Palmer
    Eric Palmer
    Participant

    Thanks again!

You must be logged in to reply to this topic.