gerardog/gsudo

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

Lostion1 opened this issue · 1 comments

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:

  • Windows version:
    Win11 23H2 - German
  • gsudo version:
    gsudo v2.5.1 (Branch.tags-v2.5.1.Sha.25d89fcac99b25534108804cb843fcbebe05a872)

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.