Home > database >  C# WPF application permissions questions
C# WPF application permissions questions

Time:11-15

I'm writing a C# WPF application that:

  1. Collects hardware information through WMI (with ManagementObjectSearcher)
  2. Captures processes' ETW draw events to measure FPS (with TraceEventSession)

I use Setup Project's installer to distribute the app. But, after installing on another computer, exe only opens with admin rights.

Google didn't help me to find the answer to:

  1. Why does my app runs without permission on my PC?
  2. Which task requires permissions and how should I know about it?
  3. Is there a way to solve the problem without permission?
  4. Why doesn't my app ask for permissions as other apps do?

I would greatly appreciate an answer to one or all of these questions! Thanks.

CodePudding user response:

Many operations that involve the WMI management interfaces require admin rights, that's just a fact. You didn't exactly specify what you do there, but querying some hardware information is likely to require this.

To test what call exactly requires admin rights, run the app on your computer without admin rights and check which call fails. You can even debug your app in that mode (just make sure you don't start Visual Studio as admin).

To make your app require admin rights, create an application manifest file (Use the "Application Manifest" template in the "new file" window) and add a line requestedExecutionLevel below the <requestedPrivileges> node as follows:

      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>

This will result in Windows asking for admin rights each time the App is started. This is a global setting for the whole application. It is not possible to ask for the permission only if you need it.

CodePudding user response:

I have this problem and I know why and why your program does not recognize Permission and has free access. Even considering that you configured the code correctly. Well, my friend, this is because you have to write your permutation class on the controller inside the bracket as a property and let the controller of that page know that this page is in Access to who should be with the same property perm checker. [1=Permission Check]

CodePudding user response:

[PermissionCheck="admin"]

public class ProductControllers:Controller

  public IActionResult index
 
         return view
 
  • Related