gerardog / gsudo

Sudo for Windows
https://gerardog.github.io/gsudo
MIT License
5.07k stars 136 forks source link

Issue: Can run Nano with sudo/gsudo #356

Closed markox92 closed 1 month ago

markox92 commented 1 month ago

Issue Description

I want to run nano as admin but when I run with sudo I have error nano: The term 'nano' is not recognized as a name of a cmdlet,

Steps to Reproduce

  1. Run with sudo and gsudo all is same.

Screenshots

gsudo --debug nano test.txt
Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --debug nano test.txt
Debug: Applying workaround for target app installed via MSStore.
Debug: Command to run: C:\Windows\system32\cmd.exe /v:on /s /c ""C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.2.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoLogo -NoProfile -Command "nano test.txt""
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 13024
Debug: Caller SID: S-1-5-21-4123966719-774669528-3486007807-1001
Debug: Elevating process: C:\Program Files\gsudo\2.5.0\gsudo.exe --debug gsudoelevate 13024 S-1-5-21-4123966719-774669528-3486007807-1001 All 00:00:00
Debug: Service process started.
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_669C51F7A9D4B9FE530E0FB146A5052E8FB81A5C3EFF9A9CB83033971EE9BB11.
Debug: Creating target process: C:\Windows\system32\cmd.exe /v:on /s /c ""C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.2.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoLogo -NoProfile -Command "nano test.txt""
Debug: Process token successfully substituted.
nano: The term 'nano' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Debug: Process exited with code 1

https://github.com/gerardog/gsudo/assets/159203552/5769536c-bfeb-4c62-8e49-1b851c375702

Context:

gerardog commented 1 month ago

Hi! Love your console colors! (Feel free to share! 😊) Question.

Do you have nano.exe in your $env:PATH ? Can you please paste the result of Get-Command 'nano'?

Or maybe... have you created a nano function in your $PROFILE? Assuming that last answer is true.: When you do gsudo nano and a new pwsh.exe -c "nano" -noprofile is run... it's unable to find 'nano' because the profile is not loaded, and nano.exe is not in the path.

You can tell gsudo to load the powershell profile with gsudo config PowerShellLoadProfile true. If your profile loads too slowly to load it on each elevation, you could add nano's path to $PATH.

makes sense?

markox92 commented 1 month ago

Screenshot 2024-05-28 195404

gsudo config PowerShellLoadProfile true is solve this problem, profile is loaded fast so no problem, thanks.

About terminal colors here is with starship prompt.

        {
            "background": "#0D1117",
            "black": "#000D1C",
            "blue": "#2B4FFF",
            "brightBlack": "#666666",
            "brightBlue": "#5C78FF",
            "brightCyan": "#5AC8FF",
            "brightGreen": "#9891FF",
            "brightPurple": "#5EA2FF",
            "brightRed": "#DE72FF",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#A3A0FF",
            "cursorColor": "#BDC0DA",
            "cyan": "#28B9FF",
            "foreground": "#C9CCE6",
            "green": "#8E76FF",
            "name": "Modern",
            "purple": "#2883FF",
            "red": "#EF56FF",
            "selectionBackground": "#98AEC9",
            "white": "#F1F1F1",
            "yellow": "#8069FF"
        }

Screenshot 2024-05-28 195747

gerardog commented 1 month ago

Thanks for sharing, I'll try them! Since the problem is gone, I'll close the issue now.