#209988 - 2015-02-20 07:49 PM
VB.net and TPM out parameters
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I'm hitting my head against the wall and I can't google anything that helps.
I am trying to write a VB.net app to check the status of the TPM on laptops, but I cannot get the out parameters to work. If life were simple, this would work:
Public Sub GetTPM()
Dim colItems As New ManagementObjectSearcher("\\.\ROOT\CIMV2\Security\MicrosoftTpm", "SELECT * FROM Win32_ProviderEx Where Name=""Win32_TpmProvider""")
For Each objItem As ManagementObject In colItems.Get()
'Dim TPMActivated As Object = objItem.InvokeMethod("IsActivated", Nothing, Nothing)
'Dim TPMEnabled As Object = objItem.InvokeMethod("IsEnabled", Nothing, Nothing)
'Dim TPMOwned As Object = objItem.InvokeMethod("IsOwned", Nothing, Nothing)
' TextBox2.Text = TPMActivated.ToString
Next
End Sub
Needless to say, it doesn't. I have the bitlocker portion reading the data correctly, so I doubt it is permissions at all.
This if the ref page, but there isn't much for me to go on. If someone has any helpful tips I'd appreciate it.
https://msdn.microsoft.com/en-us/library/aa376454(v=vs.85).aspx
|
|
Top
|
|
|
|
#209992 - 2015-02-23 01:53 PM
Re: VB.net and TPM out parameters
[Re: Lonkero]
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Dim colItems As New ManagementObjectSearcher("\\.\ROOT\CIMV2\Security\MicrosoftTpm", "SELECT * FROM Win32_ProviderEx Where Name=""Win32_TpmProvider""")
For Each objItem As ManagementObject In colItems.Get()
Dim TPMEnabled As Object
Dim result = objItem.InvokeMethod("IsEnabled", TPMEnabled)
TextBox2.Text = TPMEnabled.ToString
Next
System.Management.ManagementException: This method is not implemented in any class at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass) at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args) at BitlockerManager.Form1.GetTPM() in c:\users\wheelerc\documents\visual studio 2013\Projects\BitlockerManager\BitlockerManager\Form1.vb:line 87
|
|
Top
|
|
|
|
#209994 - 2015-02-23 02:35 PM
Re: VB.net and TPM out parameters
[Re: Radimus]
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Got it... What a PITA
Public Sub GetTPM()
Dim scope As ManagementScope = New ManagementScope("\\.\root\CIMV2\Security\MicrosoftTpm")
Dim query As SelectQuery = New SelectQuery("Win32_Tpm")
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
Dim mo As ManagementObject
For Each mo In searcher.Get()
Dim TPMActivated As ManagementBaseObject = mo.InvokeMethod("IsActivated", Nothing, Nothing)
Dim TPMEnabled As ManagementBaseObject = mo.InvokeMethod("IsEnabled", Nothing, Nothing)
Dim TPMOwned As ManagementBaseObject = mo.InvokeMethod("IsOwned", Nothing, Nothing)
TextBox2.Text = TPMActivated("IsActivated") & " " & TPMEnabled("IsEnabled") & " " & TPMOwned("IsOwned")
Next
End Sub
|
|
Top
|
|
|
|
#210000 - 2015-02-24 02:37 PM
Re: VB.net and TPM out parameters
[Re: Lonkero]
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Yea, if your PC doesn't have TPM, it will not have the WMI key.
This is pt 2:
Public Sub SetTPM()
Dim scope As ManagementScope = New ManagementScope("\\.\root\CIMV2\Security\MicrosoftTpm")
Dim query As SelectQuery = New SelectQuery("Win32_Tpm")
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
Dim mo As ManagementObject
For Each mo In searcher.Get()
Dim inParams As ManagementBaseObject = mo.GetMethodParameters("SetPhysicalPresenceRequest")
inParams("Request") = 10
Dim RC1 As ManagementBaseObject = mo.InvokeMethod("SetPhysicalPresenceRequest", inParams, Nothing)
If RC1("returnValue") <> 0 Then
MsgBox("Error setPhysicalPresenceRequest")
Else
MsgBox("SetPPR exited with code: " & RC1("returnValue"))
Dim objGetPPT As ManagementBaseObject = mo.InvokeMethod("GetPhysicalPresenceTransition", Nothing, Nothing)
Dim GetPPT As String = objGetPPT("Transition")
MsgBox(GetPPT)
Select Case GetPPT
Case 0
MsgBox("No user action is needed to perform a TPM physical presence operation.")
Case 1
MsgBox("To perform a TPM physical presence operation, the user must shutdown the computer and then turn it back on by using the power button. The user must be physically present at the computer to accept or reject the change when prompted by the BIOS.")
Case 2
MsgBox("To perform a TPM physical presence operation, the user must restart the computer by using a warm reboot. The user must be physically present at the computer to accept or reject the change when prompted by the BIOS.")
Case 3
MsgBox("The required user action is unknown.")
End Select
End If
Next
End Sub
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 484 anonymous users online.
|
|
|