0% found this document useful (0 votes)
30 views

Script Wmi

This code uses Windows Management Instrumentation (WMI) to retrieve system information from the local computer. It first queries the Win32_ComputerSystem class to get the manufacturer, model, system type, host name, and logged in user. It then checks if a Trusted Platform Module (TPM) is present by querying the Win32_Tpm class. If a TPM exists, it calls the TPM's IsActivated method to determine if the TPM is activated.

Uploaded by

api-322090954
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Script Wmi

This code uses Windows Management Instrumentation (WMI) to retrieve system information from the local computer. It first queries the Win32_ComputerSystem class to get the manufacturer, model, system type, host name, and logged in user. It then checks if a Trusted Platform Module (TPM) is present by querying the Win32_Tpm class. If a TPM exists, it calls the TPM's IsActivated method to determine if the TPM is activated.

Uploaded by

api-322090954
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System.

Management;

// create management class object


ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
//collection to store all management objects
ManagementObjectCollection moc = mc.GetInstances();
if(moc.Count != 0)
{
foreach (ManagementObject mo in mc.GetInstances())
{
// display general system information
Console.WriteLine("\nMachine Make: {0}\nMachine Model: {1}\nSystem Type: {2}\nHost Name: {3}\nLogon User Name:
{4}\n",
mo["Manufacturer"].ToString(),
mo["Model"].ToString(),
mo["SystemType"].ToString(),
mo["DNSHostName"].ToString(),
mo["UserName"].ToString());
}
}
//wait for user action
Console.ReadLine();
bool isTpmPresent;
UInt32 status = 0;
object[] wmiParams = null;
// create management class object
ManagementClass mc = new ManagementClass("/root/CIMv2/Security/MicrosoftTpm:Win32_Tpm");
//collection to store all management objects
ManagementObjectCollection moc = mc.GetInstances();
// Retrieve single instance of WMI management object
ManagementObjectCollection.ManagementObjectEnumerator moe = moc.GetEnumerator();
moe.MoveNext();
ManagementObject mo = (ManagementObject)moe.Current;
if (null == mo)
{
isTpmPresent = false;
Console.WriteLine("\nTPM Present: {0}\n", isTpmPresent.ToString());
}
else
{
isTpmPresent = true;
Console.WriteLine("\nTPM Present: {0}\n", isTpmPresent.ToString());
}
if (isTpmPresent) // Query if TPM is in activated state
{
wmiParams = new object[1];
wmiParams[0] = false;
status = (UInt32)mo.InvokeMethod("IsActivated", wmiParams);
if (0 != status)
{
Console.WriteLine("The WMI method call {0} returned error status {1}", "IsActivated", status);
}
else
{
Console.WriteLine("TPM Status: {0}", status);
}
}

You might also like