Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyway to execute anything "elevated" ? #25

Open
mocallins opened this issue Aug 1, 2023 · 12 comments
Open

Anyway to execute anything "elevated" ? #25

mocallins opened this issue Aug 1, 2023 · 12 comments

Comments

@mocallins
Copy link

I've found a few examples of how to modify a batch file to elevate, but none of them seem to work.
Any suggestions ?

@oleg-shilo
Copy link
Owner

You can install sudo from choco (https://community.chocolatey.org/packages/gsudo)

sudo notepad

starts notepad elevated. I just tested it

@mocallins
Copy link
Author

mocallins commented Aug 1, 2023 via email

@mocallins
Copy link
Author

Got gsudo installed.
Works from the command line, but not from the script i defined in Shell-X

@oleg-shilo
Copy link
Owner

oleg-shilo commented Aug 2, 2023

I tested it. Seems to work as expected:

run-elevated

image

@mocallins
Copy link
Author

mocallins commented Aug 2, 2023 via email

@oleg-shilo
Copy link
Owner

I would not expect it to be different (win10 vs win8).
But who knows :(

It might be about the way sudo behave in your environment.

What you can try is just to have a simple hello-world style app that always executes the arguments it receives as an elevated process. Basically the replacement for sudo.

static void Main(string[] args)
{
     var startInfo = new ProcessStartInfo();
     startInfo.UseShellExecute = true;
     startInfo.WorkingDirectory = Environment.CurrentDirectory;
     startInfo.FileName = args[0];
     startInfo.Arguments = "\"" +string.Join( "\" \"", args.Skip(1).ToArray()) + "\"";
     startInfo.Verb = "runas";

     Process.Start(startInfo);
}

@mocallins
Copy link
Author

gsudo is working.

The script i have defined, does not seem to be getting executed from the shell-x context menu.
The script works from the command line and double click in the desktop, just not via the context menu

@oleg-shilo
Copy link
Owner

gsudo is working.
The script i have defined, does not seem to be getting executed from the shell-x context menu.

These two statements contradict each other. When you use gsudo you are asking it to start and then execute what you have passed to it so when you execute gsudo + args from cmd prompt it behaves as expected but when from the context menu then it fails to start the args. So it does not work in your environment as it does in Win10.

Thus I suggested you write your own gsudo where you have full control. IE you can wait until new process exists. You can even debug it.

@mocallins
Copy link
Author

mocallins commented Aug 4, 2023 via email

@oleg-shilo
Copy link
Owner

Sorry, it looks like we are stuck in the loop.

Forget about the command prompt for a moment.

This is what I know from your problem description:

  1. You can execute (from the shell context menu) a batch file containing a single command to run some executable (e.g. notepad.exe)
  2. You cannot execute (from the shell context menu) a batch file containing complex command that starts with sudo (e.g. sudo notepad.exe)

Is it correct?

If it is then you have a problem with gsudo.exe (sudo is nothing else but a shim to gsudo.exe). For example, gsudo can exit immediately after starting and make an impression that it fails.

You also know from me that the problem is specific to your environment. I shared with you the desktop recording demonstrating that the solution works on Win10 just fine.

I also described for you the possible solution - implementing your own gsudo.exe equivalent.

All this puts you in a reasonable position to tackle the problem.

@mocallins
Copy link
Author

mocallins commented Aug 5, 2023 via email

@oleg-shilo
Copy link
Owner

Great. Then your problem seems to be solved.

===============

As a suggestion, please consider not using an email client for posting messages to GitHub but messaging directly from the GitHub issues page instead. As you can see on this page all your messages have unnessesary "previous message" and also loose formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants