Add Open PowerShell window here as administrator in Windows 10  

Page 6 of 7 FirstFirst ... 4567 LastLast

  1. Posts : 9
    10
       #50

    Hi. This doesn't work on folders that has single quote character ' in their names, e.g.
    Code:
    Oma'sNest
    It looks like a PowerShell window is trying to run, but it'll disappear eventually. FYI, I'm on LTSC 2019.
      My Computer

  2. Brink's Avatar
    Posts : 60,538
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #51

    hunggnuh85 said:
    Hi. This doesn't work on folders that has single quote character ' in their names, e.g.
    Code:
    Oma'sNest
    It looks like a PowerShell window is trying to run, but it'll disappear eventually. FYI, I'm on LTSC 2019.
    The character is breaking the ability to get the folder name to open to it.
      My Computers


  3. Posts : 9
    10
       #52

    Brink said:
    The character is breaking the ability to get the folder name to open to it.
    Alright, so it's a limitation by design. Anyway, there aren't many folders that have that character, so it's still fine. Thank you.
      My Computer


  4. Posts : 13
    Windows 10
       #53

    Brink said:
    The character is breaking the ability to get the folder name to open to it.
    I have been pulling my hair out trying to find a solution for this. Powershell 7 doesn't have this problem:

    C:\Program Files\PowerShell\7\pwsh.exe -WindowStyle Hidden -RemoveWorkingDirectoryTrailingCharacter -WorkingDirectory "%V!" -Command "Start-Process 'C:\Program Files\PowerShell\7\pwsh.exe' -Verb runAS;Exit"


    But I can't for the life of me figure out how to get Powershell 5 to open as Admin to the current folder if the folder has an apostrophe present. Does anyone have a working command for this?

    - - - Updated - - -

    So someone on the PowerShell Discord came up with a pretty crazy method that works. Figured I would share it here. But I'm warning you... it's not pretty.

    Here's the registry value:

    Code:
    powershell -EncodedCommand JABjAG8AbQBtAGEAbgBkACAAPQAgAFsAYwBvAG4AdgBlAHIAdABdADoAOgBUAG8AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKABbAFMAeQBzAHQAZQBtAC4AVABlAHgAdAAuAEUAbgBjAG8AZABpAG4AZwBdADoAOgBVAG4AaQBjAG8AZABlAC4ARwBlAHQAQgB5AHQAZQBzACgAIgBTAGUAdAAtAEwAbwBjAGEAdABpAG8AbgAgAGAAIgAkACgARwBlAHQALQBMAG8AYwBhAHQAaQBvAG4AKQBgACIAIgApACkACgBTAHQAYQByAHQALQBQAHIAbwBjAGUAcwBzACAAUABvAHcAZQByAHMAaABlAGwAbAAgAC0AQQByAGcAdQBtAGUAbgB0AEwAaQBzAHQAIAAiAC0ARQBuAGMAbwBkAGUAZABDAG8AbQBtAGEAbgBkACAAJABjAG8AbQBtAGEAbgBkACAALQBOAG8ARQB4AGkAdAAiACAALQBWAGUAcgBiACAAcgB1AG4AYQBzAA==
    It was created by the following:

    Code:
    $command = @'
    $command = [convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("Set-Location `"$(Get-Location)`""))
    Start-Process Powershell -ArgumentList "-EncodedCommand $command -NoExit" -Verb runas
    '@
    [convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($command))
    Not the most elegant solution in the world, but it works!
      My Computer


  5. Posts : 9
    10
       #54

    Great. Hope Brink would notice and make this a perfect tutorial.

    - - - Updated - - -

    cultmethod said:

    So someone on the PowerShell Discord came up with a pretty crazy method that works. Figured I would share it here. But I'm warning you... it's not pretty.

    Here's the registry value:

    Not the most elegant solution in the world, but it works!
    Btw, may you share the link to the Discord channel? I think your post is the first publicly available solution on the www for this issue
      My Computer


  6. Posts : 13
    Windows 10
       #55

    I got one better for you guys. A StackOverflow user who has a ton of experience guided me to a much more robust solution:

    Run Windows PowerShell (5.1) as admin (Even in folders with an apostrophe or special character):

    Code:
    powershell.exe -WindowStyle Hidden -NoProfile -Command "Start-Process -Verb RunAs powershell.exe -ArgumentList \"-NoExit -Command Push-Location \\\"\"%V/\\\"\"\"
    Run CMD (Command Prompt) as admin (Even in folders with an apostrophe or special character):

    Code:
    powershell.exe -WindowStyle Hidden -NoProfile -Command "Start-Process -Verb RunAs cmd.exe -ArgumentList \"/k pushd \"\"%V/\"\"\"
    All credit goes to mklement0 here: windows - What registry commands allow me to run PowerShell 5 / CMD as admin from the right click context menu from a folder that has an apostrophe in it? - Stack Overflow
      My Computer


  7. Posts : 9
    10
       #56

    cultmethod said:
    I got one better for you guys. A StackOverflow user who has a ton of experience guided me to a much more robust solution:

    Run Windows PowerShell (5.1) as admin (Even in folders with an apostrophe or special character):
    It turns out that these commands (including the encoded one) have issues with folders containing ` or $ characters.
    ` may not be popular, but $ is quite common (My$Money, Finance$Test).

    The CMD tweak from this tutorial works perfectly, I have not found a situation where it doesn't work. Its command contains special parameters, don't know if it would help suggest some ideas for you:
    Code:
    @="cmd /c echo|set/p=\"%V\"|powershell -NoP -W 1 -NonI -NoL \"SaPs 'cmd' -Args '/c \"\"\"cd /d',$([char]34+$Input+[char]34),'^&^& start /b cmd.exe\"\"\"' -Verb RunAs\""
      My Computer

  8. Brink's Avatar
    Posts : 60,538
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #57

    cultmethod said:
    I got one better for you guys. A StackOverflow user who has a ton of experience guided me to a much more robust solution:

    Run Windows PowerShell (5.1) as admin (Even in folders with an apostrophe or special character):

    Code:
    powershell.exe -WindowStyle Hidden -NoProfile -Command "Start-Process -Verb RunAs powershell.exe -ArgumentList \"-NoExit -Command Push-Location \\\"\"%V/\\\"\"\"
    Thank you. REG files in tutorial updated.
      My Computers


  9. Posts : 454
    Win7 Pro X64, Win10 Pro x640
       #58

    Brink said:
    Thank you. REG files in tutorial updated.
    @Brink

    Thank you for updating the tutorials. Could you update the corresponding tutorials for unelevated Powershell 5, elevated and unelevated PowerShell 7, elevated and unelevated Command Prompt, and, if necessary, elevated and non-elevated Terminal please?

    Thanks!
      My Computer

  10. Brink's Avatar
    Posts : 60,538
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #59

    bamajon1974 said:
    @Brink

    Thank you for updating the tutorials. Could you update the corresponding tutorials for unelevated Powershell 5, elevated and unelevated PowerShell 7, elevated and unelevated Command Prompt, and, if necessary, elevated and non-elevated Terminal please?

    Thanks!
    The current command prompt context menus already work with an apostrophe.

    I'm not able to get it to work with the Windows Terminal context menus yet.
      My Computers


 

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 12:41.
Find Us




Windows 10 Forums