Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the current account has permissions to use WMI #28

Closed
adhip94 opened this issue Sep 27, 2022 · 4 comments
Closed

Check if the current account has permissions to use WMI #28

adhip94 opened this issue Sep 27, 2022 · 4 comments

Comments

@adhip94
Copy link

adhip94 commented Sep 27, 2022

Is your feature request related to a problem? Please describe.
Is it possible to create a method to check if the user account/current account has permissions to use WMI? Or during initialization throw an exception indicating the same?

Describe the solution you'd like
A method or an exception while initializing the class indicating the user does not have permissions to use WMI

Describe alternatives you've considered
None yet.

Additional context
None.

@Jinjinov
Copy link
Owner

I have never hear that WMI would require permissions to use on the local machine.

According to this, you don't need any special permissions:
https://stackoverflow.com/questions/24295301/does-wmi-access-in-net-required-administrative-privileges

You only need permissions to use WMI on a remote computer, but my library doesn't do that.

Do you have an example where Hardware.Info would require any special permissions?

@adhip94
Copy link
Author

adhip94 commented Sep 28, 2022

I have a customer who uses this on their machines. In this case our application which uses Hardware.Info to verify if ram, disk storage etc. is available at startup fails since application is not able to access underlying OS functionalities, which causes WMI to fail. Hence I requested for a method/check to verify if WMI is accessible or not.

@Jinjinov
Copy link
Owner

I see. It would really help me if you would provide me with the steps to replicate this failure, so I would know what the problem is.

Just show me the minimal code necessary for this failure to happen.

@Jinjinov
Copy link
Owner

Jinjinov commented Oct 2, 2022

I didn't find any mentions of WMI failing on a local machine due to lack of permissions.

If you don't show me how this failure happens - what exception is thrown - then I can't do anything to fix it.

If the problem is that the user needs administrator privileges, then you can check that yourself:
https://stackoverflow.com/questions/5953240/check-for-administrator-privileges-in-c-sharp

using System.Security.Principal;

bool isAdministrator;
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
    WindowsPrincipal principal = new WindowsPrincipal(identity);
    isAdministrator = principal.IsInRole(WindowsBuiltInRole.Administrator);
}

I will not add this to my library.

@Jinjinov Jinjinov closed this as completed Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants