C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,857 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I would like to use something like the following C# code to check whether the system it is on has a TPM, and of which version it is.
[...]
using System.Management;
[...]
System.Management.ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2\\Security\\MicrosoftTpm", "SELECT * FROM Win32_Tpm");
ManagementObjectCollection tpmCollection = searcher.Get();
foreach (ManagementObject tpm in tpmCollection)
{
string tpmVersion = tpm["SpecVersion"].ToString();
name = "TPM Version: " + tpmVersion;
}
Does this code require to be run in admin mode to work? I am asking since the class documentation says something about "Full trust for the immediate caller." in the section on .NET framework security.
Win32_Tpm needs to be executed as Admin
(can be tested with WMICodeCreator as Admin or not (access denied))