Unity3d request user authorisation (OSX)

So basically my Unity program would need to modify hosts file on OSX and that need admin privilege to write. If i try to access it i got

UnauthorizedAccessException: Access to the path "/private/etc/hosts" is denied.

How do I pop a “XXX wants to make changes: Enter your password to allow this.” window just like the screenshot I attached below?

I did some extensive Google search but I couldn’t find anything useful.

Any suggestion would be appreciated.

Haha, funny that I found this thread because I’m also trying to write my own website blocker in Unity. Did you ever find a solution?

edit:

        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.FileName = "sudo";
        p.StartInfo.Arguments = "chmod 757 /etc/hosts";
        p.Start();

Seems like something that could be abused, but this seems to work for me (changes permission, then you can write – could set it back to 755 when you’re done) – I’m only making this app for myself anyway.

1 Like

@libra34567 have you found a solution? I need to start a process with elevated privileges as well without sudo command