Niels Bosma
Niels Bosma

Reputation: 11508

macos + C# : how can I start process with sudo prompt

I have an application built in C# .dotnet 6 on macos.

I want the application to be able to seamlessly update itself.

It's downloads the latest pkg and my problem is how I run it.

I want to start this process using "sudo installer -pkg /tmp/mypackage.pkg -target /" but sudo ask for password on the standard input.

How can I start a process with escalated privileges where the user permissions are asked first through something like:

enter image description here

Upvotes: 0

Views: 587

Answers (2)

Victor Zambrano
Victor Zambrano

Reputation: 19

You could try the option -S of sudo for accepting the password from standard input. After use echo password and | to pass the password to the command:

echo myPassword | sudo -S installer -pkg /tmp/mypackage.pkg -target

Upvotes: 0

Slava Knyazev
Slava Knyazev

Reputation: 6081

You can use AppleScript to create a graphical authentication prompt:

#!/bin/sh
osascript -e "do shell script \"$*\" with administrator privileges"

Other methods: Is there any graphical "sudo" for Mac OS X?

Upvotes: 2

Related Questions