Add Open PowerShell window here as administrator in Windows 10  

Page 7 of 10 FirstFirst ... 56789 ... LastLast

  1. Posts : 1,203
    11 Home
       #60
      My Computers


  2. Posts : 1,203
    11 Home
       #61

    Update:
    eleposh2.zip
      My Computers


  3. Posts : 519
    Win7 Pro X64, Win10 Pro x640
       #62

    hdmi said:
    Update:
    eleposh2.zip
    What do the files in the archive do?
      My Computer


  4. Posts : 1,203
    11 Home
       #63

    bamajon1974 said:
    What do the files in the archive do?
    They let you add/remove the Shift+Right-click context menu option to Open PowerShell here / Open PowerShell here as administrator. The 'as administrator' option requires you to create a task in Task Scheduler that it uses to bypass the UAC prompt, this task has to be created manually (per the instructions in the included README.txt file).

    My solution differs from all the other common methods that let you add such a command because 1/ it avoids the typical 'flashing' of an auxiliary/intermediary window that some people find to be annoying/distracting and 2/ it works regardless of whether the 'Open here' folderpath contains special characters and 3/ it respects user customizations of both (individually) the regular and the 'as administrator' PowerShell windows. For it to work, it also requires you to add the two copies of the shortcuts from the WinX menu in which customizations are stored, i.e. by running the Add_Shotcuts.vbs script, only one time for setting it up.

    The scripts also contain some comments to get a clear overview of which files/folders/names/paths they use, to make it easier/faster for you to edit the scripts, should you want to move and/or rename some of the files/folders to suit your own preference.

    The only real downsides are that you need to perform a few simple steps to set it up─albeit you only need to set it up one time─and there's a bunch of files there, so it may look a bit overcomplicated as a result. But IMO (and IME) the pros still outweigh the cons anyway, after all.
      My Computers


  5. Posts : 519
    Win7 Pro X64, Win10 Pro x640
       #64

    hdmi said:
    They let you add/remove the Shift+Right-click context menu option to Open PowerShell here / Open PowerShell here as administrator. The 'as administrator' option requires you to create a task in Task Scheduler that it uses to bypass the UAC prompt, this task has to be created manually (per the instructions in the included README.txt file).

    My solution differs from all the other common methods that let you add such a command because 1/ it avoids the typical 'flashing' of an auxiliary/intermediary window that some people find to be annoying/distracting and 2/ it works regardless of whether the 'Open here' folderpath contains special characters and 3/ it respects user customizations of both (individually) the regular and the 'as administrator' PowerShell windows. For it to work, it also requires you to add the two copies of the shortcuts from the WinX menu in which customizations are stored, i.e. by running the Add_Shotcuts.vbs script, only one time for setting it up.

    The scripts also contain some comments to get a clear overview of which files/folders/names/paths they use, to make it easier/faster for you to edit the scripts, should you want to move and/or rename some of the files/folders to suit your own preference.

    The only real downsides are that you need to perform a few simple steps to set it up─albeit you only need to set it up one time─and there's a bunch of files there, so it may look a bit overcomplicated as a result. But IMO (and IME) the pros still outweigh the cons anyway, after all.
    Ahh I see. Very nice.

    Just out of curiosity, did you happen to read the thread in tenforums customization I posted a year ago or so about how to exclude the addition of "open command prompt here" or "open powershell window here" and their elevated analogs to library folders and backgrounds? If you try to open a command prompt or powershell window in a symbolic or hard link (like libraries), nothing happens but the entries created in Directory, Directory, and Drive registry keys add to libraries anyway and there is no obvious way how to exclude. Would you happen to know how?

    Thanks
      My Computer


  6. Posts : 1,203
    11 Home
       #65

    bamajon1974 said:
    Would you happen to know how?
    All my scripts work properly for me with all libraries it seems like. The only way that I have been able to get an explorer.EXE error dialog window to appear so far has been after I Shift-Right-click in/on the Libraries (special folder type thing) that appears in the Nav pane of File Explorer. If, however, I go to %AppData%\Microsoft\Windows\Libraries and I Shift-Right-click in/on that one, all my scripts work normally for me. Special folders are not real folder locations nor are symbolic links. Rather, they merely are visual representations of locations that are concocted by File Explorer itself, to give the fake impression that what you are seeing is an actual symbolic link. I like to refer to these visuals as fata morganas, appearances that occur in the Microsoft-controlled district of the Great Digital Desert. Another example or similar type of behavior, that has also been confusing a lot of people is the Network neighborhood, not to mention the (now gone) HomeGroup fiasco. Unquestionably, these things all have the Midas Touch. My advice? Steer clear from them. If you try the opposite, you'll regret it for the rest of your life.
      My Computers


  7. Posts : 519
    Win7 Pro X64, Win10 Pro x640
       #66

    hdmi said:
    All my scripts work properly for me with all libraries it seems like. The only way that I have been able to get an explorer.EXE error dialog window to appear so far has been after I Shift-Right-click in/on the Libraries (special folder type thing) that appears in the Nav pane of File Explorer. If, however, I go to %AppData%\Microsoft\Windows\Libraries and I Shift-Right-click in/on that one, all my scripts work normally for me. Special folders are not real folder locations nor are symbolic links. Rather, they merely are visual representations of locations that are concocted by File Explorer itself, to give the fake impression that what you are seeing is an actual symbolic link. I like to refer to these visuals as fata morganas, appearances that occur in the Microsoft-controlled district of the Great Digital Desert. Another example or similar type of behavior, that has also been confusing a lot of people is the Network neighborhood, not to mention the (now gone) HomeGroup fiasco. Unquestionably, these things all have the Midas Touch. My advice? Steer clear from them. If you try the opposite, you'll regret it for the rest of your life.
    Understood. If you are interested, here is a link to the thread. There was never a resolution.
    How to exclude libraries from custom right-click menu entries
    The key is to use some sort of AppliesTo or AppliesTo NOT string in the registry menu entries to exclude the fake Library folders but there is very little documentation on how to use the Strings or how anyone would exclude libraries.

    Thanks!
      My Computer


  8. Posts : 705
    Windows 10/11
       #67

    @Brink I saw that there were a number of iterations of this context menu item script. It looked like every topic had been covered, so I was a little surprised to find that there are several characters, that are valid for folder paths, that will result in an error. Those characters are $, [, and ` Here are some example folder paths that will error out:

    $a b
    [a b
    `a b

    So, I set about to create a one-liner script that could handle all valid Windows folder paths. It turns out to be an almost "you can't get there from here" problem.

    At first, the answer seems simple. Just use single quotes around the path and then PowerShell won't expand anything. While that approach will fix the examples above, there will then be the problem that any path with a ' will fail. And I'm sure people use a single quote in folder names at least as frequently as those other characters. So, that's not going to work. And, even though there's the -LiteralPath option, it doesn't help with the initial parsing of the script.

    Edit: Solvable by passing the path via a set command for the non-admin PowerShell, and via the registry for the admin PowerShell. Updated scripts here:

    Add Open PowerShell window here as administrator in Windows 10
    Last edited by LesFerch; 19 Dec 2023 at 23:17.
      My Computer


  9. Posts : 1,203
    11 Home
       #68

    LesFerch said:
    @Brink I saw that there were a number of iterations of this context menu item script. It looked like every topic had been covered, so I was a little surprised to find that there are several characters, that are valid for folder paths, that will result in an error. Those characters are $, [, and ` Here are some example folder paths that will error out:

    $a b
    [a b
    `a b

    So, I set about to create a one-liner script that could handle all valid Windows folder paths. It turns out to be an almost "you can't get there from here" problem.

    At first, the answer seems simple. Just use single quotes around the path and then PowerShell won't expand anything. While that approach will fix the examples above, there will then be the problem that any path with a ' will fail. And I'm sure people use a single quote in folder names at least as frequently as those other characters. So, that's not going to work. And, even though there's the -LiteralPath option, it doesn't help with the initial parsing of the script.

    So, after almost giving up, I realized the only way to solve it (short of going with an external script or exe) is to pass the folder path via a temp file. That way, the path itself never gets in the way of the command parsing. So, here is the end result:

    For a regular PowerShell window:

    cmd /c echo %v>"%temp%\path.txt" && start powershell -noL -noE -c $a = (gc -Path "%temp%\path.txt" -raw).trim(); set-location -literalpath $a

    For an Administrator PowerShell window:

    cmd /c echo %v>"%temp%\path.txt" && start powershell -WindowS Hidden -noP -c Start-Process -v RunAs powershell.exe '-noL -noE -c $a = (gc -Path "%temp%\path.txt" -raw).trim(); set-location -literalpath $a'

    Because these scripts use %temp%, they must be created as REG_EXPAND_SZ entries. Here's an export of the shell entries (i.e. right-click on a folder). I also used shell32 strings for the titles so it's automatically multilingual.

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CURRENT_USER\Software\Classes\Directory\shell\PowerShell]
    @="@shell32.dll,-8508"
    "Icon"="powershell.exe"
    
    [HKEY_CURRENT_USER\Software\Classes\Directory\shell\PowerShell\command]
    @=hex(2):63,00,6d,00,64,00,20,00,2f,00,63,00,20,00,65,00,63,00,68,00,6f,00,20,\
      00,25,00,76,00,3e,00,22,00,25,00,74,00,65,00,6d,00,70,00,25,00,5c,00,70,00,\
      61,00,74,00,68,00,2e,00,74,00,78,00,74,00,22,00,20,00,26,00,26,00,20,00,73,\
      00,74,00,61,00,72,00,74,00,20,00,70,00,6f,00,77,00,65,00,72,00,73,00,68,00,\
      65,00,6c,00,6c,00,20,00,2d,00,6e,00,6f,00,4c,00,20,00,2d,00,6e,00,6f,00,45,\
      00,20,00,2d,00,63,00,20,00,24,00,61,00,20,00,3d,00,20,00,28,00,67,00,63,00,\
      20,00,2d,00,50,00,61,00,74,00,68,00,20,00,22,00,25,00,74,00,65,00,6d,00,70,\
      00,25,00,5c,00,70,00,61,00,74,00,68,00,2e,00,74,00,78,00,74,00,22,00,20,00,\
      2d,00,72,00,61,00,77,00,29,00,2e,00,74,00,72,00,69,00,6d,00,28,00,29,00,3b,\
      00,20,00,73,00,65,00,74,00,2d,00,6c,00,6f,00,63,00,61,00,74,00,69,00,6f,00,\
      6e,00,20,00,2d,00,6c,00,69,00,74,00,65,00,72,00,61,00,6c,00,70,00,61,00,74,\
      00,68,00,20,00,24,00,61,00,00,00
    
    
    [HKEY_CURRENT_USER\Software\Classes\Directory\shell\PowerShellAsAdmin]
    @="@shell32.dll,-37448"
    "HasLUAShield"=""
    "Icon"="powershell.exe"
    
    [HKEY_CURRENT_USER\Software\Classes\Directory\shell\PowerShellAsAdmin\command]
    @=hex(2):63,00,6d,00,64,00,20,00,2f,00,63,00,20,00,65,00,63,00,68,00,6f,00,20,\
      00,25,00,76,00,3e,00,22,00,25,00,74,00,65,00,6d,00,70,00,25,00,5c,00,70,00,\
      61,00,74,00,68,00,2e,00,74,00,78,00,74,00,22,00,20,00,26,00,26,00,20,00,73,\
      00,74,00,61,00,72,00,74,00,20,00,70,00,6f,00,77,00,65,00,72,00,73,00,68,00,\
      65,00,6c,00,6c,00,20,00,2d,00,57,00,69,00,6e,00,64,00,6f,00,77,00,53,00,20,\
      00,48,00,20,00,2d,00,4e,00,6f,00,50,00,20,00,2d,00,63,00,20,00,53,00,74,00,\
      61,00,72,00,74,00,2d,00,50,00,72,00,6f,00,63,00,65,00,73,00,73,00,20,00,2d,\
      00,76,00,20,00,52,00,75,00,6e,00,41,00,73,00,20,00,70,00,6f,00,77,00,65,00,\
      72,00,73,00,68,00,65,00,6c,00,6c,00,2e,00,65,00,78,00,65,00,20,00,27,00,2d,\
      00,6e,00,6f,00,4c,00,20,00,2d,00,6e,00,6f,00,45,00,20,00,2d,00,63,00,20,00,\
      24,00,61,00,20,00,3d,00,20,00,28,00,67,00,63,00,20,00,2d,00,50,00,61,00,74,\
      00,68,00,20,00,22,00,25,00,74,00,65,00,6d,00,70,00,25,00,5c,00,70,00,61,00,\
      74,00,68,00,2e,00,74,00,78,00,74,00,22,00,20,00,2d,00,72,00,61,00,77,00,29,\
      00,2e,00,74,00,72,00,69,00,6d,00,28,00,29,00,3b,00,20,00,73,00,65,00,74,00,\
      2d,00,6c,00,6f,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,2d,00,6c,00,69,\
      00,74,00,65,00,72,00,61,00,6c,00,70,00,61,00,74,00,68,00,20,00,24,00,61,00,\
      27,00,00,00
    You could have saved yourself a lot of time and effort by simply examining the solution I wrote and posted in post #61 above, which, although it's several years old now, still works like a charm at least for me on both Windows 10 and 11.
      My Computers


  10. Posts : 705
    Windows 10/11
       #69

    hdmi said:
    You could have saved yourself a lot of time and effort by simply examining the solution I wrote and posted in post #61 above, which, although it's several years old now, still works like a charm at least for me on both Windows 10 and 11.
    I did examine your solution. It's similar to one I've implemented myself and works very well, as long as Windows Script Host has not been disabled and VBScript has not been uninstalled. The version I wrote uses JScript, so it won't be affected in the future by VBScript becoming an optional install or being removed altogether. However, it's still not going to work on machines where WSH has been disabled.

    The goal here was to provide a replacement one-liner for the registry that only uses Cmd and PowerShell and will work with any valid Windows folder name.
      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 01:19.
Find Us




Windows 10 Forums