Add Open PowerShell window here as administrator in Windows 10  

Page 5 of 5 FirstFirst ... 345

  1. Posts : 1
    Win 10
       #40

    For the shift + right click as admin argument is not being forwarded to subshell.
    Original:
    "PowerShell -Command "Start-Process cmd -ArgumentList '/s,/k,pushd && start PowerShell -NoExit && exit' -Verb RunAs""
    Change:
    "PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd && start PowerShell -NoExit set-location -LiteralPath %V && exit' -Verb RunAs\""
    Updated reg file is attached
      My Computer

  2. Brink's Avatar
    Posts : 56,482
    64-bit Windows 10 Pro for Workstations build 21364
    Thread Starter
       #41

    conwayc said:
    For the shift + right click as admin argument is not being forwarded to subshell.
    Original:
    "PowerShell -Command "Start-Process cmd -ArgumentList '/s,/k,pushd && start PowerShell -NoExit && exit' -Verb RunAs""
    Change:
    "PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd && start PowerShell -NoExit set-location -LiteralPath %V && exit' -Verb RunAs\""
    Updated reg file is attached
    Thank you conwayc. I have updated the .bat files to use the new command.
      My Computers


  3. Posts : 370
    Win7 Pro X64, Win10 Pro x640
       #42

    The updated reg files do not work in some cases. When right-clicking some directories, and executing "open powershell as admin", the following error is provided and the window opens in %windir%/system32/ directory.

    Can you correct please?

    Set-Location : A positional parameter cannot be found that accepts argument 'D.'.
    At line:1 char:1
    + set-location -LiteralPath C:\Users\Jonathan D. Woodward\Desktop\Windo ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

    Add Open PowerShell window here as administrator in Windows 10-powershell.png
      My Computer

  4. Matthew Wai's Avatar
    Posts : 5,146
    Windows 10 Home 20H2
       #43

    bamajon1974 said:
    + set-location -LiteralPath C:\Users\Jonathan D. Woodward\Desktop\Windo ...
    What is the full path?
      My Computer


  5. Posts : 370
    Win7 Pro X64, Win10 Pro x640
       #44

    Matthew Wai said:
    What is the full path?
    It happens with multiple paths....so for example, if I right click on C:\Users\<Profile Name>.... or C:\Temp or C:\Program Files folders and click powershell, run as admin, etc.
      My Computer

  6. Brink's Avatar
    Posts : 56,482
    64-bit Windows 10 Pro for Workstations build 21364
    Thread Starter
       #45

    bamajon1974 said:
    The updated reg files do not work in some cases. When right-clicking some directories, and executing "open powershell as admin", the following error is provided and the window opens in %windir%/system32/ directory.

    Can you correct please?

    Set-Location : A positional parameter cannot be found that accepts argument 'D.'.
    At line:1 char:1
    + set-location -LiteralPath C:\Users\Jonathan D. Woodward\Desktop\Windo ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

    Add Open PowerShell window here as administrator in Windows 10-powershell.png
    Matthew Wai said:
    What is the full path?
    It appears to be an issue when a folder or directory includes a space in the name.

    Using this below seems to working well. I'll update the .bat files to use this below for now after some more testing.

    @="PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd %V && start PowerShell -NoExit && exit' -Verb RunAs\""
      My Computers


  7. Posts : 370
    Win7 Pro X64, Win10 Pro x640
       #46

    Got it. How do you fix the registry modification to account for folders with spaces?

    Brink said:
    It appears to be an issue when a folder or directory includes a space in the name.

    Using this below seems to working well. I'll update the .bat files to use this below for now after some more testing.

    @="PowerShell -Command \"Start-Process cmd -ArgumentList '/s,/k,pushd %V && start PowerShell -NoExit && exit' -Verb RunAs\""
      My Computer

  8. Brink's Avatar
    Posts : 56,482
    64-bit Windows 10 Pro for Workstations build 21364
    Thread Starter
       #47

    bamajon1974 said:
    Got it. How do you fix the registry modification to account for folders with spaces?
    I used %V after pushd instead of using -Literalpath so it will push the name with spaces.

    So far, it's working fine on all directory names and spaces.

    The .bat files are now updated using this.
      My Computers


  9. Posts : 370
    Win7 Pro X64, Win10 Pro x640
       #48

    That change seems to fix the issue of the directory names with spaces. Thank you!

    Brink said:
    I used %V after pushd instead of using -Literalpath so it will push the name with spaces.

    So far, it's working fine on all directory names and spaces.

    The .bat files are now updated using this.
      My Computer

  10. Brink's Avatar
    Posts : 56,482
    64-bit Windows 10 Pro for Workstations build 21364
    Thread Starter
       #49

    bamajon1974 said:
    That change seems to fix the issue of the directory names with spaces. Thank you!
    You're most welcome.
      My Computers


 
Page 5 of 5 FirstFirst ... 345

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 21:03.
Find Us




Windows 10 Forums