Add Open PowerShell window here as administrator in Windows 10  

Page 10 of 10 FirstFirst ... 8910

  1. Posts : 745
    Windows 10/11
       #90

    hdmi said:
    Be aware that cmd.exe is limited to 8,191 characters.
    I tested long paths, but stopped after getting to 2000 or so characters. I can't imagine we'll see a lot of users hitting the 8K or so limit, but I get your point. It would be nice if the solution handled all edge cases.
      My Computer


  2. Posts : 521
    Win7 Pro X64, Win10 Pro x640
       #91

    Good morning. Does anyone know how to modify the default non-elevated shift+right-click Open PowerShell Window for directories and drives (in HKCR\directory\Shell\Powershell and HKCR\drive\shell\Powershell) to NOT show up when shift+right clicking Libraries? For example, if one shift+right clicks the Library icon in the explorer navigation pane and tries to open Powershell, an error message pops up because the console cannot open a hard link. I think that an AppliesTo Not string and keyword is the way to modify the relevant registry keys but I am not sure how to implement.

    I have asked this question in the past with no solution so I thought I would ask on this thread since it has received some attention this past week.

    Thanks!
      My Computer


  3. Posts : 745
    Windows 10/11
       #92

    bamajon1974 said:
    Good morning. Does anyone know how to modify the default non-elevated shift+right-click Open PowerShell Window for directories and drives (in HKCR\directory\Shell\Powershell and HKCR\drive\shell\Powershell) to NOT show up when shift+right clicking Libraries?
    Those are not the entries that affect the Libraries folder. It's the ones under background.

    Unfortunately, any entries under background will show up for Libraries when you right right-click (or shift-right-click when the entry includes Extended) and there does not appear to be any way to change that.

    I don't think I've ever right-clicked or shift-right-clicked Libraries before, so I've never noticed this.
      My Computer


  4. Posts : 521
    Win7 Pro X64, Win10 Pro x640
       #93

    LesFerch said:
    Those are not the entries that affect the Libraries folder. It's the ones under background.

    Unfortunately, any entries under background will show up for Libraries when you right right-click (or shift-right-click when the entry includes Extended) and there does not appear to be any way to change that.

    I don't think I've ever right-clicked or shift-right-clicked Libraries before, so I've never noticed this.

    Sorry for the delay in my reply. Holidays kept me busy.

    To demonstrate, please open File Explorer, shift+right-click on the Libraries Icon in the Navigation Pane, and click on the "Open PowerShell window here" option. An error message pops up about the file/action not having an associated app. The same thing happens if you shift+right-click on the window background in the main library window (the window that shows pictures, documents, videos, music, etc. libraries). This effect is from the native shift+right-click PowerShell/CMD windows baked into windows.

    If you go to HKCR\librarybackground\shell registry key, there is nothing present by default. Apparently, the "open powershell window here" right-click menu entry appears in the library folder because it is present in the HKCR\directory and HKCR\directory keys.

    If you examine at @Brink 's take ownership context menu (Add Take Ownership to Context Menu in Windows 10), key directories/drives are excluded by adding AppliesTo NOT strings. I am guessing that it may be possible to resolve the context menu entries with powershell/cmd in libraries by including a similar string in the HKCR\directory key and target libraries but I am not sure how point the string to hard links. Any ideas?

    Thanks!
      My Computer


  5. Posts : 745
    Windows 10/11
       #94

    bamajon1974 said:
    To demonstrate...
    No need to demonstrate. I see the same error. I just said that I hadn't ever noticed that in the past because I never tried to do that before. Since library folders are a combined view of one or more folders, there is no corresponding real path to open. It's easily confused because, to begin with, there is only one folder associated with each library.

    Apparently, the "open powershell window here" right-click menu entry appears in the library folder because it is present in the HKCR\directory and HKCR\directory keys.
    Yes, specifically the "background" subkey:

    [HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell]
    @="@shell32.dll,-8508"
    "Extended"=""
    "NoWorkingDirectory"=""
    "ShowBasedOnVelocityId"=dword:00639bc8

    [HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command]
    @="powershell.exe -noexit -command Set-Location -literalPath '%V'"



    And, keep in mind, HKCR is a virtual view that combines the classes entries from HKLM and HKCU. The real location is here:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Powershell]
    @="@shell32.dll,-8508"
    "Extended"=""
    "NoWorkingDirectory"=""
    "ShowBasedOnVelocityId"=dword:00639bc8

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Powershell\command]
    @="powershell.exe -noexit -command Set-Location -literalPath '%V'"



    If you examine at @Brink 's take ownership context menu (Add Take Ownership to Context Menu in Windows 10), key directories/drives are excluded by adding AppliesTo NOT strings.
    The AppliesTo option accepts actual paths. Libraries are not real paths, so I can't see any way to exclude them.
      My Computer


  6. Posts : 521
    Win7 Pro X64, Win10 Pro x640
       #95

    The AppliesTo option accepts actual paths. Libraries are not real paths, so I can't see any way to exclude them.[/QUOTE]

    Ugh, that's what I thought. Thank you for the clarification. An odd but not unexpected oversite by MS.

    Another question about the default shift+right-click "open powershell window here" option. I would prefer to disable the default right-click menu entries altogether. The context menu entries can be disabled by adding a "LegacyDisable" or "ProgrammaticAccessOnly" string to the appropriate [HKLM\software\classes\directory\shell\powershell] and analogous background keys. However, an unexpected side effect of disabling the default keys is greying out the powershell menu entries in File Explorer. So if you disable either the directory or background directory (forget which one) right-click entry, the Powershell and AdminPowershell entries in File Explorer (File > Open Windows PowerShell) are also greyed out.

    I am guessing that somehow the right-click menu entry for powershell is connected to the ribbon commands. Would you know how to resolve this issue?

    Thanks!
      My Computer


  7. Posts : 745
    Windows 10/11
       #96

    bamajon1974 said:
    The context menu entries can be disabled by adding a "LegacyDisable" or "ProgrammaticAccessOnly" string to the appropriate [HKLM\software\classes\directory\shell\powershell] and analogous background keys. However, an unexpected side effect of disabling the default keys is greying out the powershell menu entries in File Explorer. So if you disable either the directory or background directory (forget which one) right-click entry, the Powershell and AdminPowershell entries in File Explorer (File > Open Windows PowerShell) are also greyed out.
    Add "LegacyDisable" or "ProgrammaticAccessOnly" (makes no difference) as a string value to the directory\background\shell PowerShell entry only. That will eliminate the PowerShell option from shift-right-click on the background and Libraries, but retain the PowerShell options in Explorer where applicable.
      My Computer


  8. Posts : 745
    Windows 10/11
       #97

    garlin said:
    Why not? It doesn't correctly display the path until you fix the Code Page.
    Yes, your code works fine with Unicode paths with the addition of a CHCP command:

    Code:
    cmd /c chcp 65001 & echo "%V%" | powershell $Path = $Input.Trim() -replace '''',''''''; Start-Process powershell -ArgumentList $('-NoExit -Command "Set-Location -LiteralPath ''' + $Path + '''"') -Verb RunAs
    The pipe takes some time, causing the Cmd window to be visible noticeably longer than the Reg method, but I thought it would be a good idea to document this anyhow.

    Both this method and the Reg method will trip on a folder name that contains an environment variable, such as %OS%, but I think it's safe to say that would be extremely rare.
      My Computer


 

Tutorial Categories

Add Open PowerShell window here as administrator in Windows 10 Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:27.
Find Us




Windows 10 Forums