Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Looking for an err message

Reply
 
Old 06-02-2009   #1 (permalink)
OldDog


 
 

Looking for an err message

I am writting script to determine if the Trusted Platform Module (TPM)
is turned on and active.

If the TPM is turned on in the BIOS I have no problems checking it's
status.
My problem is when it is turned off, I do not get any error messages.

Here is the code;

Set objWMIService = GetObject("WinMgmts:
{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" _
& "." & "\root\CIMV2\Security\MicrosoftTpm") '<-- all one line
Set objItems = objWMIService.InstancesOf("Win32_Tpm")

For Each objItem In objItems

rvaluea = objItem.IsEnabled(A)
rvalueb = objItem.IsActivated(B)
rvaluec = objItem.IsOwned(C)
If A Then
WScript.Echo "TPM Is Enabled: " & A
Else
WScript.Echo "TPM Is Enabled: " & A
End If

If B Then
WScript.Echo "TPM Is Activated: " & B
Else
WScript.Echo "TPM Is Activated: " & B

End If

If C Then
WScript.Echo "TPM Is Owned: " & C
Else
WScript.Echo "TPM Is Owned: " & C

End If
Next

Any ideas on how to tell if there is no responce from the TPM?

I tried this

Set objWMIService = GetObject("WinMgmts:
{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" _
& "." & "\root\CIMV2\Security\MicrosoftTpm") '<-- all one line
Set objItems = objWMIService.InstancesOf("Win32_Tpm")

If Err.Number <> 0 Then
WScript.Echo "Trusted Platform Module may be turned off"
End If

But I get err 0 regardless of the state of the device.

My System SpecsSystem Spec
Old 06-02-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Looking for an err message


"OldDog" <mikef2691@xxxxxx> wrote in message
news:1e15be35-8822-4167-883a-7d7193ba24c0@xxxxxx
Quote:

>I am writting script to determine if the Trusted Platform Module (TPM)
> is turned on and active.
>
> If the TPM is turned on in the BIOS I have no problems checking it's
> status.
> My problem is when it is turned off, I do not get any error messages.
>
> Here is the code;
>
> Set objWMIService = GetObject("WinMgmts:
> {impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" _
> & "." & "\root\CIMV2\Security\MicrosoftTpm") '<-- all one line
> Set objItems = objWMIService.InstancesOf("Win32_Tpm")
>
> For Each objItem In objItems
>
> rvaluea = objItem.IsEnabled(A)
> rvalueb = objItem.IsActivated(B)
> rvaluec = objItem.IsOwned(C)
> If A Then
> WScript.Echo "TPM Is Enabled: " & A
> Else
> WScript.Echo "TPM Is Enabled: " & A
> End If
>
> If B Then
> WScript.Echo "TPM Is Activated: " & B
> Else
> WScript.Echo "TPM Is Activated: " & B
>
> End If
>
> If C Then
> WScript.Echo "TPM Is Owned: " & C
> Else
> WScript.Echo "TPM Is Owned: " & C
>
> End If
> Next
>
> Any ideas on how to tell if there is no responce from the TPM?
>
> I tried this
>
> Set objWMIService = GetObject("WinMgmts:
> {impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" _
> & "." & "\root\CIMV2\Security\MicrosoftTpm") '<-- all one line
> Set objItems = objWMIService.InstancesOf("Win32_Tpm")
>
> If Err.Number <> 0 Then
> WScript.Echo "Trusted Platform Module may be turned off"
> End If
>
> But I get err 0 regardless of the state of the device.
I cannot find any script examples using Win32_Tpm, but the variables A, B,
and C are never defined or given a value. If the rest of the code is OK (I
cannot tell), then this might work:
=========
For Each objItem In objItems
rvaluea = objItem.IsEnabled
rvalueb = objItem.IsActivated
rvaluec = objItem.IsOwned
If rvaluea Then
WScript.Echo "TPM Is Enabled"
Else
WScript.Echo "TPM Is Disabled"
End If

If rvalueb Then
WScript.Echo "TPM Is Activated"
Else
WScript.Echo "TPM Is Not Activated"
End If

If rvaluec Then
WScript.Echo "TPM Is Owned"
Else
WScript.Echo "TPM Is Not Owned"
End If
Next
======
I would recommend using Option Explicit and not using "On Error Resume
Next". For example, I would use the following at the beginning of the
script:
==========
Option Explicit

Dim objWMIService, objItems, objItem
Dim rvaluea, rvalueb, rvaluec
=========
Possibly if TPM is turned off, there are no objects in the collection
objItems. You can detect this because the For Each loop will just skip and
none of the statements in the loop will run. There will not necessarily be
an error. You might want to use code similar to:
======
Dim blnOn
blnOn = False
For Each objItem In objItems
rvaluea = objItem.IsEnabled
rvalueb = objItem.IsActivated
rvaluec = objItem.IsOwned
blnOn = True
If (rvaluea = True) Then
WScript.Echo "TPM Is Enabled"
Else
WScript.Echo "TPM Is Disabled"
End If

If (rvalueb = True) Then
WScript.Echo "TPM Is Activated"
Else
WScript.Echo "TPM Is Not Activated"
End If

If (rvaluec = True) Then
WScript.Echo "TPM Is Owned"
Else
WScript.Echo "TPM Is Not Owned"
End If
Next
If (blnOn = False) Then
Wscript.Echo "TPM is turned off in BIOS"
End If

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
new message window uploading photos error message Live Mail
Email message attachments to a received windows mail message Vista mail
Retrieving IMAP message stalls when message contains large attachment. Vista mail
Deleting a message in an open window opens the next message in Inb Vista mail
delete message returns me to previous message in the inbox Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46