Reputation: 830
I'm writing a C# WPF application that:
ManagementObjectSearcher
)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:
I would greatly appreciate an answer to one or all of these questions! Thanks.
Upvotes: 0
Views: 600
Reputation: 17185
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.
Upvotes: 3