Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can you gain administrator permission in .NET program?

Can you gain administrator permission in .NET program?

Scheduled Pinned Locked Moved C#
csharpc++question
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Kenedy S Kom
    wrote on last edited by
    #1

    I have noticed that why anti virus, and other programs can gain administrator access when the app started when computer starts? And why not .net created application? If I set to request administrator level in exe manifest, it will prompt user for permission, and it is very annoying since this application is automatically started at computer startup. How do I gain administrator permission (or at least the user login permission) without asking for password? Why native exe can do it and why not .net exe? Should we all move to C++ instead of supporting C#? Any idea? or complains?

    J D 2 Replies Last reply
    0
    • J John Kenedy S Kom

      I have noticed that why anti virus, and other programs can gain administrator access when the app started when computer starts? And why not .net created application? If I set to request administrator level in exe manifest, it will prompt user for permission, and it is very annoying since this application is automatically started at computer startup. How do I gain administrator permission (or at least the user login permission) without asking for password? Why native exe can do it and why not .net exe? Should we all move to C++ instead of supporting C#? Any idea? or complains?

      J Offline
      J Offline
      Jacob D Dixon
      wrote on last edited by
      #2

      http://www.developerfusion.com/code/7987/making-a-net-app-run-on-vista-with-administrator-priviledges/[^] Check that out.

      <requestedExecutionLevel level="asInvoker" uiAccess="false" />

      Should run under the the user that started the application.

      1 Reply Last reply
      0
      • J John Kenedy S Kom

        I have noticed that why anti virus, and other programs can gain administrator access when the app started when computer starts? And why not .net created application? If I set to request administrator level in exe manifest, it will prompt user for permission, and it is very annoying since this application is automatically started at computer startup. How do I gain administrator permission (or at least the user login permission) without asking for password? Why native exe can do it and why not .net exe? Should we all move to C++ instead of supporting C#? Any idea? or complains?

        D Offline
        D Offline
        David Ewen
        wrote on last edited by
        #3

        It is my understanding that apps like anti-virus programs appear to have admin access from their client tools because they talk to a windows service which is running with elevated privileges. The service is installed when you install the app (which you do get a UAC prompt for) after that point the client tools use IPC to communicate with the privileged service. There may be (and most probably are) exceptions to this rule, I have not done much work in this area. So if your app really needs admin privileges (it probably shouldn’t) a workaround would be to install a windows service which performs the admin functions and communicate with that.

        J 1 Reply Last reply
        0
        • D David Ewen

          It is my understanding that apps like anti-virus programs appear to have admin access from their client tools because they talk to a windows service which is running with elevated privileges. The service is installed when you install the app (which you do get a UAC prompt for) after that point the client tools use IPC to communicate with the privileged service. There may be (and most probably are) exceptions to this rule, I have not done much work in this area. So if your app really needs admin privileges (it probably shouldn’t) a workaround would be to install a windows service which performs the admin functions and communicate with that.

          J Offline
          J Offline
          John Kenedy S Kom
          wrote on last edited by
          #4

          i see, my app is this one Writing a Folder Synchronization application[^] which i think it should have admin privileges, since it is running in background doing synchronization works, which may include synchronizing folder in C or even program files and recently i am having another project, which the application need to configure write its configuration files in its program files folder, but it does not have permission to do so, isn't this weird? for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory, shouldn't it have administrator privileges? Why microsoft need to limit the privileges of executable?

          D D 2 Replies Last reply
          0
          • J John Kenedy S Kom

            i see, my app is this one Writing a Folder Synchronization application[^] which i think it should have admin privileges, since it is running in background doing synchronization works, which may include synchronizing folder in C or even program files and recently i am having another project, which the application need to configure write its configuration files in its program files folder, but it does not have permission to do so, isn't this weird? for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory, shouldn't it have administrator privileges? Why microsoft need to limit the privileges of executable?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            John Kenedy S.Kom wrote:

            Why microsoft need to limit the privileges of executable?

            Any executable runs AS the user that launched it. There are no special restrictions on .EXE's of different types. The "security" model you're assuming is not correct. When you install, say, an anti-virus engine, it installs a service that is actually doing all the work. It usually runs under the Local System account, which has pretty much admin priv's to the entire machine. Any UI program that you use to interact with this anti-virus app always runs as YOU. This app talks to the service and tells the service what it needs to do. The service runs as the local system, giving you the ILLUSION that what you ran has admin priv's.

            John Kenedy S.Kom wrote:

            for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory

            Writing to the Program Files fold is off-limits to normal users, but not admins. But, an .EXE can be installed to other locations that the user CAN write to. All it takes is for the updater to copy down the new .EXE to the correct location, but always the one you think it does. It's also possible that when the app was installed, the security for the apps folder under the Program Files folder was opened up to allow users to write to it. Installers are written to run under administrator accounts, meaning they have free reign to configure the system, security, accounts, ... anything it needs to get the app installed and the rights it needs to do whatever it needs to.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            J 1 Reply Last reply
            0
            • J John Kenedy S Kom

              i see, my app is this one Writing a Folder Synchronization application[^] which i think it should have admin privileges, since it is running in background doing synchronization works, which may include synchronizing folder in C or even program files and recently i am having another project, which the application need to configure write its configuration files in its program files folder, but it does not have permission to do so, isn't this weird? for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory, shouldn't it have administrator privileges? Why microsoft need to limit the privileges of executable?

              D Offline
              D Offline
              David Ewen
              wrote on last edited by
              #6

              The synchronization app is exactly the kind of app that should be implemented as a windows service even without the UAC prompting issues. UAC has imposed some architecture changes, configuration files should be place in “Application Settings” directories or isolated storage which are accessible without elevation. Similarly plug-ins can be placed and loaded from those 2 locations. A self updating app could be achieved be installing a basic exe to program files and then loading the bulk of the app code into app settings so it can be replaced if needed or UAC elevation for this feature is completely understandable and the standard practice (Firefox, OpenOffice, etc) all prompt for elevation when updating.

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                John Kenedy S.Kom wrote:

                Why microsoft need to limit the privileges of executable?

                Any executable runs AS the user that launched it. There are no special restrictions on .EXE's of different types. The "security" model you're assuming is not correct. When you install, say, an anti-virus engine, it installs a service that is actually doing all the work. It usually runs under the Local System account, which has pretty much admin priv's to the entire machine. Any UI program that you use to interact with this anti-virus app always runs as YOU. This app talks to the service and tells the service what it needs to do. The service runs as the local system, giving you the ILLUSION that what you ran has admin priv's.

                John Kenedy S.Kom wrote:

                for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory

                Writing to the Program Files fold is off-limits to normal users, but not admins. But, an .EXE can be installed to other locations that the user CAN write to. All it takes is for the updater to copy down the new .EXE to the correct location, but always the one you think it does. It's also possible that when the app was installed, the security for the apps folder under the Program Files folder was opened up to allow users to write to it. Installers are written to run under administrator accounts, meaning they have free reign to configure the system, security, accounts, ... anything it needs to get the app installed and the rights it needs to do whatever it needs to.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                J Offline
                J Offline
                John Kenedy S Kom
                wrote on last edited by
                #7

                I see, thanks Dave for the answer... Then I might consider to improve my app into a service instead and also learn about IPC, since these two are really new to me. Thanks! Btw, what is the different between Local System account and the admin account? If a user is not an admin and installing the service, can the service then have the admin privileges, such as those own by anti virus?

                D 1 Reply Last reply
                0
                • J John Kenedy S Kom

                  I see, thanks Dave for the answer... Then I might consider to improve my app into a service instead and also learn about IPC, since these two are really new to me. Thanks! Btw, what is the different between Local System account and the admin account? If a user is not an admin and installing the service, can the service then have the admin privileges, such as those own by anti virus?

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  John Kenedy S.Kom wrote:

                  If a user is not an admin and installing the service,

                  If a user is not an admin, they're not installing the service. Also, even if they could, they cannot grant anything more rights than they themselves have. The only accounts that can grant admin permissions, are administrators. The Local System is the account the, well, system uses. Even Windows has to provide credentials to Windows Security.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups