Does Get method in System.Management.ManagementObjectSearcher require admin rights?

Private Coder 75 Reputation points
2023-03-20T09:53:54.86+00:00

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.

C#
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,245 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,721 Reputation points
    2023-03-20T10:22:18.7933333+00:00

    Win32_Tpm needs to be executed as Admin

    (can be tested with WMICodeCreator as Admin or not (access denied))

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful