c# - Find if Windows is OEM without WMI -
it can done using wmi.
but there simple way (similar environment.is64bitoperatingsystem)?
edit: there permission limitations on wmi. far know is64bitoperatingsystem "better" in respect, , maybe others. (please correct me if i'm wrong.)
i'm trying make sure code run, without throwing exceptions.
well, first off, environment.is64bitoperatingsystem able job without requiring special permissions because doesn't checks whatsoever. 64-bit version of .net framework hard-coded return true, , 32-bit version return false. simple that.
things going bit more complicated information wish obtain, unfortunately.
you don't how you're obtaining information through wmi, assume you're querying serialnumber property of win32_operatingsystem class, taking information know format of windows product ids determine whether os installed using oem key. if there's oem second part of key, return true, otherwise false.
of course, section of key numeric, numeric values indicating oem key. example, remember values in 600s indicate oem keys, couldn't tell ones. have master list of of these (from where, wonder?), , checking against them well. otherwise, you'll number of false negatives.
anyway, assuming that's approach (and it's 1 can think of), question becomes "how can obtain windows product id without using wmi?"
you try querying registry it, fragile approach. it's not documented in location in registry, subject change between windows versions. on current versions, it's in
hkey_local_machine\software\microsoft\windows nt\currentversion\productid to make work, you'll have handle 32-bit vs 64-bit, , application require elevation—only administrators can muck hkey_local_machine.
as far know, information not otherwise exposed win32 api. there no isoemversion function, , it's neither 1 of members of osversioninfoex structure nor 1 of flags used isos function.
there is, obviously, reason wmi exists. if want, should use it. there's nothing inherently "unsafe" it. if information wish query requires privileges access, reason , you're not going have success in finding alternate routes of accessing bypass security restrictions.
if absolutely necessary have partially-trusted code harness vast power of wmi, can create intermediate fully-trusted assembly exposes necessary functionality, , call partially-trusted assembly.
but in particular case, should question why need or want information. difference make if it's oem version of operating system? behaves identically perspective (both user , developer). if you'd given more information planning use information accomplish, might able give better suggestions.
Comments
Post a Comment