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

UseAsteriskInWMI option #76

Open
simonedd opened this issue Dec 12, 2024 · 3 comments
Open

UseAsteriskInWMI option #76

simonedd opened this issue Dec 12, 2024 · 3 comments

Comments

@simonedd
Copy link

Library version

101.0.0

OS, version, architecture (32 bit / 64 bit)

Windows 11, 64-bit

Describe the bug

This is not a bug but a clarification request. I noticed that the library provides the UseAsteriskInWMI option, which allows switching between using SELECT * and a specific list of properties in WMI queries. However, given that the library typically maps results to strongly typed objects (e.g., the BIOS class in GetBiosList), using SELECT * seems slower and unnecessary as only specific properties are extracted in the code. The documentation says is safer to use asterisk because certain WMI properties might be missing and throw an exception when queried by name, but the application will crash anyway if the property is missing because explicitly extracted a few lines above (e.g. Caption = GetPropertyString(mo["Caption"]).

@Jinjinov
Copy link
Owner

Look at the lines with _os.Version. like:

https://github.com/Jinjinov/Hardware.Info/blob/master/Hardware.Info/Windows/HardwareInfoRetrieval.cs#L335

https://github.com/Jinjinov/Hardware.Info/blob/master/Hardware.Info/Windows/HardwareInfoRetrieval.cs#L532

I admit that the possibility of someone running this code on some obscure Windows version that I haven't considered is very low, but that is exactly what happened one time, so I added this option and left it there - for the one in a million chance someone needs it.

@Jinjinov Jinjinov closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
@simonedd
Copy link
Author

I'm afraid I still don't understand. Even when using the SELECT* query, on some obscure Windows version the code will crash on this line: https://github.com/Jinjinov/Hardware.Info/blob/master/Hardware.Info/Windows/HardwareInfoRetrieval.cs#L551

@Jinjinov
Copy link
Owner

I had to go look at the old commits to figure out why I wrote this in the README file.
You are right, useAsteriskInWMI is not a very useful option.

I had a bug when I wrote that using SELECT * is safer. I didn't have the OS version check, so SELECT * actually was safer, but looking at the code, it would crash when accessing the property by name, just like you said.

I will look into useAsteriskInWMI and probably remove it (a breaking change).

@Jinjinov Jinjinov reopened this Dec 13, 2024
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