gerardog / gsudo

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

Issue: C:\Program Files (x86) not working as expected #362

Closed Lostion1 closed 3 months ago

Lostion1 commented 3 months ago

Issue Description

If i create a folder in C:\Program Files (x86) called Test (C:\Program Files (x86)\Test) then i put gsudo.exe in and make a .bat with the following:

gsudo.exe echo Test>test.txt

i get "Access denied"

Same with: gsudo.exe -s echo Test>test.txt gsudo.exe -ti echo Test>test.txt

It only works if i start an gsudo.exe shell before which defeats my purpose (i only need gsudo for certain commands).

Steps to Reproduce

  1. Create a Folder in C:\Program Files (x86) called text. Copy gsudo.exe in it.
  2. Make a .bat with gsudo.exe echo Test>test.txt or with -s or -ti switch
  3. Start the .bat with normal User permissions

Context:

gerardog commented 3 months ago

This is what's happening: When you run gsudo.exe -s echo Test>test.txt then gsudo -s echo Test is executed, which elevates echo Test as System. Then the parent CMD.EXE which is not elevated sends the results of the command to > test.txt. That operation fails.

The solution is to ensure the redirection to a file is done within the elevated context, for example with: gsudo "echo Hi! > hello.txt" which will elevate the whole thing, including the redirection.

image

Makes sense? Feel free to ask if you have any doubts. Thank you for using gsudo.