0

I am creating an application that monitors another application, if the application get close the former will restart that, and I have to create a folder in c:\ drive , if i simply run the application nothing happens but when i run that as admin it works as required. What can I do to make this application automatically start as admin without any prompt, as i want to run this application on start up, just like some antivirus programs which do not ever need admin rights.

public bool IsProcessOpen()
     {
        string name = "aProgram";
        foreach (Process clsProcess in Process.GetProcesses())
        {
            if (clsProcess.ProcessName.Contains(name))
            {
                return true;
            }
        }

        return false;
    }


    private void timer1_Tick_1(object sender, EventArgs e)
    {
        try
        {
            bool track = false;
            track =IsProcessOpen();
        if (!track)
        {
            Process firstProc = new Process();
            firstProc.StartInfo.FileName =Application.StartupPath + "\\" + fileName;
            firstProc.EnableRaisingEvents = true;

            firstProc.Start();

        }
        }
        catch (Exception)
        {
        }
    }

I dont want that the user gets UAC prompt.

  • Similar post here http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7 – Haja Maideen Jul 20 '14 at 15:15
  • The AV programs run as services, and you provide admin credentials when installing. You need to provide admin credentials at some point. When do you want to do so? – David Heffernan Jul 20 '14 at 15:20
  • This is a spying application so, i don't want the user get to know about that,how can I achieve this? Is it possible to always run the application as admin without user's knowledge? – pooja_baraskar Jul 20 '14 at 16:36
  • 1
    I don't think this is a duplicate question. The guy is asking about how to run the app as admin ON STARTUP! i.e when the PC is first booted up and there's NO one there to click 'Yes' when prompted to run as admin! – sam byte Aug 01 '18 at 16:05
  • I don’t know which idiot declared the problem to be a duplicate, and it doesn’t know the difference between a double-click to start as an administrator and an automatic start as an administrator when the machine is turned on. https://stackoverflow.com/questions/5127375/running-program-as-administrator-at-startup – huang Jun 09 '21 at 10:17
  • @HajaMaideen Do you really understand the question? Startup means when the machine turned on, not the application start by double click. – huang Jun 09 '21 at 10:21

1 Answers1

0

in windows there is something called task scheduler, there one can create the task and give the path to any specific program, choose admin rights and when to start etc. attached screenshots for your referenceCreate New Task

set trigger as run at logon

Himanshu Sourav
  • 700
  • 1
  • 10
  • 35