Hi guys!
I want to run my executable app in Windows or MAC as administrator automatically. I would like to know if its possible.
Thanks
Hi guys!
I want to run my executable app in Windows or MAC as administrator automatically. I would like to know if its possible.
Thanks
Almost certainly not possible.
Think about what you’re asking…
If your app could run as administrator just by claiming the admin rights what would be the point of any security settings put in place by the user.
sure it’s possible but unsuable in real life.
Well - that’s why I didn’t make my answer definitive :?
Options such as trashing the admin password or even trying to break the admin password just don’t fall within the realms of possibility/reasonability for installing a game/app.
Sorry, maybe I was not so clear.
I’m developing a game/app installable and I need some IO operations to run (write/read/create files). I can not write without the admin privileges.
Here’s a simple code below demonstrates this:
using UnityEngine;
using System.Collections;
using System.IO;
public class IOTest : MonoBehaviour {
void Start () {
StreamWriter w = File.CreateText(Application.dataPath + "/index.xml");
w.WriteLine("Hello world");
w.Close();
}
}
Atach to some gameobject, compile this scene and put in your “c:/Program Files/test”. Run it.
If you are not running as admin the file will be not created.
So I have some option to run my application with administrator privileges?
Thanks
Can’t speak for MAC as I’m not that familiar with it, but for Windows you should be able to write to a directory that’s part of the Users directory structure (e.g. their documents folder) without admin priviledges.
Have a dig through some windows documentation.
Yes, it’s possible. But when run inside “Program Files” in Windows needs admin privileges.
Obvious answer is not to write there.
One way that is windows specific (maybe) is to use…
string dir;
dir=System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Look at
There may be a unity specific equivalent to this but haven’t found it..
Ok, but i would like to put my game like other programs. ie some like this “C:\Program Files\EA GAMES\Battlefield 2”
Thanks for the help. I think there is one solution about this in. NET (Mono). I will try to find some solution to make it.
Use an installer.
Those I’ve used prompt the user to be in “Administrator” mode for installation.
I thought you were referring to data relevant to the program, not the program itself.
Good luck
I ran into exactly this same problem with Visual Studio 2010 last week.
Right-click/Properties on the shortcut you use to start your app, choose the compatibility tab, at the bottom of the dialog check “Run this program as an administrator”. That will always launch it as an administrator, and you will get the UAC prompt every time you start. If you just want to run as admin every once and awhile, then right-click and choose Run as administrator.
EDIT - still not clear if you are trying to do this for your dev tools, or if you want your installed app to run this way. IF it is the later, I don’t think it is possible, since even Microsoft didn’t do it with the Visual Studio install.
Your best bet is to do like VS 2010 does - if it detects it doesn’t have access to the files it needs, it gives you a dialog telling you to run in admin mode and gives instructions how to do that.
Yes! I want to do this, but requesting admin approval at application start like Steam and others programs.
I found the solution for applications compiled by Visual Studio. Hear ( Requesting Admin Approval at Application Start - CodeProject ). But I did not find a solution that works in the Unity3D. I’m still looking for a solution.
Thanks for the help of everyone so far.
This is an old thread, but does anyone have more current info on how to do something like this, where it could maybe prompt once to run my game as an admin and then not do it again, the way other games do? I’m using an updater asset built into my game, but it’s looking like it only works if somebody starts the game as an admin. Otherwise it won’t download a patch and it just hangs in the updater when the program starts.
Really all I want is for the updater to always be able to run. I don’t really care if it’s in admin mode or not, that’s just the only way so far I’m aware of that works. On my development machine I don’t have to “run as admin,” but my testers so far are needing to.
You can not add the required manifest file to Unity’s exe as an embedded resource unless Unity supports doing it which it doesn’t at the moment.
The only solution that comes to my mind is trying to launch the game using a small exe app built in VS which just runs the game and exits.
Then add the required manifest to that exe and automatically things which are run by that process will be admin elevated. If didn’t , in ProcessStartInfo set werb property to “runas”
Thanks. I’ve since found a reasonable solution and released the product . I had InnoSetup write something to the registry that tells it to run in admin mode. Not ideal probably, but it works.
Open Terminal on Mac:
sudo /Applications/Unity_201xxxx/Unity_201xxxx.app/Contents/MacOS/Unity
Replace xxx for correct version.
yours
Bruh. Almost half of all freeware has an automatic uac prompt at launch