5 Replies - 808 Views - Last Post: 18 June 2012 - 12:15 PM Rate Topic: -----

#1 Tim.Simon  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 26
  • Joined: 12-June 12

Install an app that runs as Administrator

Posted 18 June 2012 - 08:26 AM

Hello,

I have created a process that runs in the background that scans a directory for files dropped in it, and sends those files somewhere via TCP. The settings are stored in xml, and I have created a tray app so the user can start and stop the process as well as configure the system. Saving the settings requires the process to be stopped and then restarted.

I have discovered that stopping and starting the process requires the tray app to have administrator privileges. I have used the Visual Studios installer to install the program and add the tray app to Startup, but I am not sure how to set it so it will run as administrator.

Does anyone know how to do this... or even better, how to start and stop the process from the tray without it running as administrator? I greatly appreciate all comments.

Is This A Good Question/Topic? 0
  • +

Replies To: Install an app that runs as Administrator

#2 negligible  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 302
  • Joined: 02-December 10

Re: Install an app that runs as Administrator

Posted 18 June 2012 - 09:04 AM

I think you should be running this as a Windows Service and have the tray part of the program as a separate project which interacts behind the scenes with the Service.

This post has been edited by negligible: 18 June 2012 - 09:05 AM

Was This Post Helpful? 1
  • +
  • -

#3 Tim.Simon  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 26
  • Joined: 12-June 12

Re: Install an app that runs as Administrator

Posted 18 June 2012 - 09:07 AM

That is what I am doing. The service monitors the folder. The tray app is just there so the service can be configured using a UI, and to provide a way to start and stop the service.
Was This Post Helpful? 0
  • +
  • -

#4 negligible  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 302
  • Joined: 02-December 10

Re: Install an app that runs as Administrator

Posted 18 June 2012 - 09:32 AM

Okay, can you post the relevant parts of your code?

You shouldn't have to force your application to run as Administrator, it's not good for security as normal users can run it to.

I use this controller
http://msdn.microsof...y/yb9w7ytd.aspx
Was This Post Helpful? 0
  • +
  • -

#5 Tim.Simon  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 26
  • Joined: 12-June 12

Re: Install an app that runs as Administrator

Posted 18 June 2012 - 09:43 AM

Thank you for your assistance. I use both a start and stop method similar to what you posted a link for. My code for the start method follows:

        public void startEvent_Click(object sender, EventArgs e)
        {
            ServiceController service = new ServiceController("MRS TCP File Handler");
            try
            {
                TimeSpan timeout = TimeSpan.FromMilliseconds(30000);
                service.Start();
                service.WaitForStatus(ServiceControllerStatus.Running, timeout);
            }
            catch (Exception ex)
            {
                LogWriter.Log("Could not start the Service: " + ex.Message + "\n" + ex.StackTrace);
            }

            if (settings != null && settings.IsOpen)
                settings.SetStartToggle();
        }



I would prefer not to have to run as administrator, but in my testing I found that, although I can run just fine from VS, once installed it needs elevation or the service is not started or stopped.

Again, I greatly appreciate your assistance!
Was This Post Helpful? 0
  • +
  • -

#6 Tim.Simon  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 26
  • Joined: 12-June 12

Re: Install an app that runs as Administrator

Posted 18 June 2012 - 12:15 PM

To get the installer to install with admin privileges, do the following:

1. Right click on the project you want to run as administrator
2. Select Add -> New -> Application Manifest File
3. Edit the Requested Execution Level line so that it says
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />


Thank you for your help, Negligible.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1