Page 1 of 1 1
Topic Options
#209988 - 2015-02-20 07:49 PM VB.net and TPM out parameters
Radimus Moderator Offline
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:
 Code:
    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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#209989 - 2015-02-21 12:52 AM Re: VB.net and TPM out parameters [Re: Radimus]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Obviously this is kix forum for starters...

Something like this should work:
 Code:
Dim bool TPMEnabled = false
Dim uint idontcare = objItem.InvokeMethod("IsEnabled", TPMEnabled)
            


Edited by Lonkero (2015-02-21 12:56 AM)
_________________________
!

download KiXnet

Top
#209990 - 2015-02-21 01:47 AM Re: VB.net and TPM out parameters [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Coming to think about it... You might need to specify byref in the arts. Or whatever the keyword is in vb
_________________________
!

download KiXnet

Top
#209991 - 2015-02-21 02:38 AM Re: VB.net and TPM out parameters [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Was curious enough to check. Vb does not require you to pass any keywords. So in theory my example is correct
_________________________
!

download KiXnet

Top
#209992 - 2015-02-23 01:53 PM Re: VB.net and TPM out parameters [Re: Lonkero]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
 Code:
        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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#209993 - 2015-02-23 02:03 PM Re: VB.net and TPM out parameters [Re: Radimus]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Well. Let me play with it a bit...
_________________________
!

download KiXnet

Top
#209994 - 2015-02-23 02:35 PM Re: VB.net and TPM out parameters [Re: Radimus]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Got it... What a PITA

 Code:
    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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#209995 - 2015-02-23 02:55 PM Re: VB.net and TPM out parameters [Re: Radimus]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what the... that looks weird. but indeed it was invokemethod() I thought needed some research.
_________________________
!

download KiXnet

Top
#209996 - 2015-02-23 03:17 PM Re: VB.net and TPM out parameters [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that does not work for me either. probably because my desktop does not have TPM.

I tried a simplistic approach:
 Code:
Imports System.Management
Module Module1
    Sub Main()
        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
        Dim thing() As Object = {False}
        For Each mo In searcher.Get()
            mo.InvokeMethod("IsActivated", thing)
            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)
            Console.WriteLine(thing(0).ToString)
            Console.WriteLine(TPMActivated("IsActivated") & " " & TPMEnabled("IsEnabled") & " " & TPMOwned("IsOwned"))
        Next
        Console.ReadKey()
    End Sub

End Module


none of if errors out, but none of it also prints nothing and indeed with debugger I can see it does not even enter the for each loop on my computer. could try the laptop.
_________________________
!

download KiXnet

Top
#210000 - 2015-02-24 02:37 PM Re: VB.net and TPM out parameters [Re: Lonkero]
Radimus Moderator Offline
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:

 Code:
    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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.056 seconds in which 0.021 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org