Client Management Suite

 View Only
Expand all | Collapse all

Vb Script Custom Inventory

SRJaeger

SRJaegerJan 24, 2019 02:54 PM

Alex Hedley

Alex HedleyJan 28, 2019 12:32 PM

Alex Hedley

Alex HedleyFeb 05, 2019 08:23 AM

  • 1.  Vb Script Custom Inventory

    Posted Jan 04, 2019 11:10 AM

    I need a vb script for a custom inventory on TPM.  I have a working script to geives me the results I need IF the pc has TPM activated.  However, if it is set to deactivat, then the script reurns no results and in the databse I get nulls.  The problem is, if I run the script against a pc that is not connected , I also get  no results and nulls in db.  I had posted the script on Stack Overflow and was given an IF statement to include.  However, it does not post the results as 'not applicable". Hoping Symantec can see what the issue is so I can complete this.  This is the working script (which does not work  on a pc that does not have TPM activated:

     

    '===================================================================================================================

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

                                           

     

    '===================================================================================================================

    'Create instance of Altiris NSE component

    '===================================================================================================================

    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

     

    For each objInfo in colItems

     

    dim objDataRow

    set objDataRow = objDataClass.AddRow

     

    WScript.Echo objInfo.IsActivated_InitialValue

    WScript.Echo objInfo.IsEnabled_InitialValue

    WScript.Echo objInfo.IsOwned_InitialValue

    WScript.Echo objInfo.ManufacturerId

    WScript.Echo objInfo.ManufacturerVersion

    WScript.Echo objInfo.ManufacturerVersionInfo

    WScript.Echo objInfo.PhysicalPresenceVersionInfo

    WScript.Echo objInfo.SpecVersion

     

    objDataRow.SetField 0, objInfo.IsActivated_InitialValue

    objDataRow.SetField 1, objInfo.IsEnabled_InitialValue

    objDataRow.SetField 2, objInfo.IsOwned_InitialValue

    objDataRow.SetField 3, objInfo.ManufacturerId

    objDataRow.SetField 4, objInfo.ManufacturerVersion

    objDataRow.SetField 5, objInfo.ManufacturerVersionInfo

    objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo

    objDataRow.SetField 7, objInfo.SpecVersion

     

    Next

    nse.SendQueued

     

    '===================================================================================================================

    This is the script that is supposed to ouput Not applicable but doesn't:


    '===================================================================================================================

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

                                           

     

    '===================================================================================================================

    'Create instance of Altiris NSE component

    '===================================================================================================================

    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

    dim objDataRow


    If colItems.Count > 0 Then
         For each objInfo in colItems
          set objDataRow = objDataClass.AddRow

     objDataRow.SetField 0, objInfo.IsActivated_InitialValue
            objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
            objDataRow.SetField 2, objInfo.IsOwned_InitialValue
            objDataRow.SetField 3, objInfo.ManufacturerId
            objDataRow.SetField 4, objInfo.ManufacturerVersion
            objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
            objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
            objDataRow.SetField 7, objInfo.SpecVersion
        Next

    Else

        Set objDataRow = objDataClass.AddRow

        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"

    End If


     

    objDataRow.SetField 0, objInfo.IsActivated_InitialValue

    objDataRow.SetField 1, objInfo.IsEnabled_InitialValue

    objDataRow.SetField 2, objInfo.IsOwned_InitialValue

    objDataRow.SetField 3, objInfo.ManufacturerId

    objDataRow.SetField 4, objInfo.ManufacturerVersion

    objDataRow.SetField 5, objInfo.ManufacturerVersionInfo

    objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo

    objDataRow.SetField 7, objInfo.SpecVersion

     

     

    nse.SendQueued

     

    '===================================================================================================================



  • 2.  RE: Vb Script Custom Inventory

    Posted Jan 05, 2019 05:29 AM
    First thing I would do it make the script standalone, take all the Altiris stuff out of it and test it just taking to WMI. Add logging everywhere, output to the screen, a lot, popup, anything that could be useful. Log when it hits the if, log when it hits the else, etc. Do you know if “colItems” returns a empty object, a null, what if no computer is found. Have you used WMI Explorer before? https://github.com/vinaypamnani/wmie2/blob/master/README.md SELECT * FROM Win32_Tpm - if the computer doesn’t exist this could cause the issue.


  • 3.  RE: Vb Script Custom Inventory

    Posted Jan 07, 2019 07:08 AM

    In answer to your question, I have not used WMI.  My only exposure is through looking at scripts others have written and trying to understand it or through other posts here.

    Over the weekend I looked into this  bit , It might be that if TPM is not enabled on the pc, then the class does not exist.  

    At a cmd prompt, wmic /namespace:\\root\cimv2\security\microsofttpm path win32_tpm get IsActivated_InitialValue on a pc where TPM is not enabled gives me  --No Instances(s) Available. 

    So this might be kicking off an error.  However, the person from Stack Overflow that gave me --If colItems.Count > 0 Then..  said this should handle it as the Count would not be >0 .

    If the class does not exist, then I just need the script to write that to objDataRow.SetField 0, objInfo.IsActivated_InitialValue, or if it does exist, complete the other Fields.



  • 4.  RE: Vb Script Custom Inventory

    Posted Jan 07, 2019 07:30 AM

    That assumes colItems returns an object that has a count.



  • 5.  RE: Vb Script Custom Inventory

    Posted Jan 07, 2019 07:56 AM

    That makes sense.  I just do not know how to write this.



  • 6.  RE: Vb Script Custom Inventory

    Posted Jan 07, 2019 11:47 AM

    Try to assign some default values (like No) for your mandatory variables and let it overwrite by the real value afterwards. Or replace null value by “No” prior to sending them to the SMP.

    This is part of the script we use:

     

    Dim oWMITPM, GetTPMinfo, colTPM, oTPM, sIsEnabled, sIsActivated, sIsOwned

    Dim ReturnCode

     

    Dim ObjInstance, objItem, objItems, bIsEnabled, bIsActivated, bIsOwned

    Dim IS1, IS2, IS3

    Set oWMITPM = GetObject("WinMgmts:{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" & "." & "\root\CIMV2\Security\MicrosoftTpm")

     

    Set objItems = oWMITPM.InstancesOf("Win32_Tpm")

     

    sIsEnabled = "NO"

    sIsActivated = "NO"

    sIsOwned = "NO"

     

    For Each objItem In objItems

     

                    sIsEnabled = "YES"

                    LogToFile "  -----> The TPM Chip has been turned on inside the BIOS"

     

                    Is2 = objItem.IsActivated(bIsActivated)

     

                    Is3 = objItem.IsOwned(bIsOwned)

     

                    If bIsActivated Then

                                    sIsActivated = "YES"

                                    LogToFile "  -----> The TPM Chip has been activated inside the BIOS"

                    Else

                                    sIsActivated= "NO"

                                    LogToFile "  -----> The TPM Chip has been NOT been activated inside the BIOS"

                    End If

     

                    If bIsOwned Then

                                    sIsOwned = "YES"

                                    LogToFile "  -----> The ownership of the TPM Chip has been taken"

                    Else

                                    sIsOwned = "NO"

                                    LogToFile "  -----> Their is no owner of the TPM Chip"

                    End If

     

    Next



  • 7.  RE: Vb Script Custom Inventory

    Posted Jan 07, 2019 11:52 AM

    Check for Null

    If IsNull(colItems) Then 
        objDataRow.SetField 1, "Not Applicable"
        ...
        objDataRow.SetField 7, "Not Applicable" 
    End if

     



  • 8.  RE: Vb Script Custom Inventory

    Posted Jan 07, 2019 02:26 PM

    Thank you both.  Alex, I do not know scripting so I really need to be handhled through this, if you can.  Where do I put the  'check for null' as you wrote?

    Does it go before?      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly), after, some place else?



  • 9.  RE: Vb Script Custom Inventory

    Posted Jan 08, 2019 04:04 AM

    Before

    If colItems.Count > 0 Then

    You could then change it to an ElseIf

    If IsNull(colItems) Then
      ...
    ElseIf colItems.Count > 0 Then
      ...
    End If

     You'd need to create the object before you can check it's existence.



  • 10.  RE: Vb Script Custom Inventory

    Posted Jan 08, 2019 11:22 AM

    Thanks again.  You have given me pieces of the puzzle so to speak but I cannot put it together COMPLETELY and make it work. I ask again if you could provide the script in its entirety.  As you have the knowledge, it probaly would take no time at all as where I have no understanding, has taken days of trial and error and messages.

    Thank you



  • 11.  RE: Vb Script Custom Inventory

    Posted Jan 08, 2019 12:00 PM

    Unfortunately I can't replicate your issue to trigger the line you need to add but this should work

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)
    
    dim objDataRow
    
    If Not IsNull(colItems) Then
        For each objInfo in colItems
            Set objDataRow = objDataClass.AddRow
    
            objDataRow.SetField 0, objInfo.IsActivated_InitialValue
            objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
            objDataRow.SetField 2, objInfo.IsOwned_InitialValue
            objDataRow.SetField 3, objInfo.ManufacturerId
            objDataRow.SetField 4, objInfo.ManufacturerVersion
            objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
            objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
            objDataRow.SetField 7, objInfo.SpecVersion
        Next
    
    Else
    
        Set objDataRow = objDataClass.AddRow
    
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    
    End If

     



  • 12.  RE: Vb Script Custom Inventory

    Posted Jan 08, 2019 12:20 PM
      |   view attached

    Thank you.  I just ran the script in Altiris and the pc wehre tpm is not activated is still showing nulls rather than 'not applicable'. Aslo the pc that had data in each column also now has a second entry with nulls.

                     
                     
                     

     



  • 13.  RE: Vb Script Custom Inventory

    Posted Jan 08, 2019 03:48 PM
    What are the Data Types for the Custom Inventory columns/fields you created?


  • 14.  RE: Vb Script Custom Inventory

    Posted Jan 08, 2019 03:59 PM
    Another useful thing you can do is check the xml that is being sent up in the event. Trapping NSEs on a Windows client https://support.symantec.com/en_US/article.HOWTO4191.html


  • 15.  RE: Vb Script Custom Inventory

    Posted Jan 09, 2019 07:06 AM
      |   view attached

    On the pc where I am not getting any results, there are two states in the BIOS-Disable/Enable. If it is then Enabled, new option is Deactivate/Activate/Clear.

    This pc like many others is in the first case-Disable.

    From  admin cmd prompt, running: wmic /namespace:\\root\cimv2\security\microsofttpm path win32_tpm get IsActivated_InitialValue produces output: No Instance(s) Available. Running the vb script in VBSEdit ther are no erros and no output.

    I understand the  set colitems and the If Not isNull which is checking for it's existence and since it is not found, should then  go the the Else statement and write those values (Not Applicable) but it doesn't.  From the wnic cmd , it seems to be saying that the class does not exist.

    If I enable the TPM then I get  results  like the pc with the data as in the screen shot attached yesterday.  Could it be an issue with this class not existing and the error not being handled by the code?

    The Data Type for the Custom inventory is String, Size=50, Key is NO and required is No. Allow multiple rows from a single computer resource is checked



  • 16.  RE: Vb Script Custom Inventory

    Posted Jan 09, 2019 07:18 AM

    I have enabled TPM on this pc that was not sending any data.  The results are shown in the screenshot of the Altiris Task-Output.jpg.

    The data is being written to the DB as in the second screen shot TPM enabled.jpg

    I don't see that there is an issue with the NSE and data being sent and received.



  • 17.  RE: Vb Script Custom Inventory

    Posted Jan 09, 2019 07:59 AM

    If you output the following what is returned?

    TypeName(colItems)

    If you add some logging after the "If" and the "Else", does the "Else" get printed?

    .

    You could be hacky and add

    On Error Resume Next

    You can check for Errors

    If Err.Number <> 0 Then
    	MsgBox("Error: " & Err.Number & " | Error (Hex): " & Hex(Err.Number) & " | Source: " &  Err.Source & " | Description: " &  Err.Description)
    	Err.Clear
    End If

     



  • 18.  RE: Vb Script Custom Inventory

    Posted Jan 14, 2019 09:29 AM
      |   view attached

    Been away from this for a few days. Thanks for the suggestions, but notknowing VB, I do not know where these are to be entered in the script.

    However as I have said before, it seems the problem exists becasue there is no WIN32_TPM on a pc where TPM is disabled.  The script I was given:

    If colItems.Count > 0 Then
         For each objInfo in colItems
          set objDataRow = objDataClass.AddRow
     ........

    ELSE

    The if does not seem to handle the actual error although logically it should- there is no colitems

    Running the script in VBSEdit, the error is when it gets to line 8:

     Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm"

    The debug error that pops up is:

    Line 8

    Column 1

    ERROR (null)

    Code 80041003

    Source (null)
     

     
     



  • 19.  RE: Vb Script Custom Inventory

    Posted Jan 14, 2019 09:41 AM

    You could try

     

    On Error Resume Next
    
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm"
    
    If Err.number <> 0 Then 
        WScript.Echo "Error connecting to: " & strComputer
    
        Set objDataRow = objDataClass.AddRow
    
        objDataRow.SetField 0, "Not Applicable"
        '...
    
    Else
    
        'Rest of Script when successful
    
    End If
    
    On Error Goto 0

     



  • 20.  RE: Vb Script Custom Inventory

    Posted Jan 15, 2019 07:20 AM

    I worked with the code above, took out all Altiris references in the existing script and just ran the script.  Now, neither pc shows any output in the task output properties.

    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    If Err.number <> 0 Then
        WScript.Echo "Error connecting to: " & strComputer

      dim objDataRow  

     Set objDataRow = objDataClass.AddRow

        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"

    Else
     

    set objDataRow = objDataClass.AddRow

     

    WScript.Echo objInfo.IsActivated_InitialValue

    WScript.Echo objInfo.IsEnabled_InitialValue

    WScript.Echo objInfo.IsOwned_InitialValue

    WScript.Echo objInfo.ManufacturerId

    WScript.Echo objInfo.ManufacturerVersion

    WScript.Echo objInfo.ManufacturerVersionInfo

    WScript.Echo objInfo.PhysicalPresenceVersionInfo

    WScript.Echo objInfo.SpecVersion

     

    objDataRow.SetField 0, objInfo.IsActivated_InitialValue

    objDataRow.SetField 1, objInfo.IsEnabled_InitialValue

    objDataRow.SetField 2, objInfo.IsOwned_InitialValue

    objDataRow.SetField 3, objInfo.ManufacturerId

    objDataRow.SetField 4, objInfo.ManufacturerVersion

    objDataRow.SetField 5, objInfo.ManufacturerVersionInfo

    objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo

    objDataRow.SetField 7, objInfo.SpecVersion

     
    End If
    On Error Goto 0



  • 21.  RE: Vb Script Custom Inventory

    Posted Jan 15, 2019 08:02 AM

    Where is your

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

    Then your loop

    For each objInfo in colItems
    ...

     



  • 22.  RE: Vb Script Custom Inventory

    Posted Jan 15, 2019 08:47 AM

    Okay- I see I left out pieces.  They are added and I still get  the error " Error connecting to:. from line 5.

    Version:0.9 StartHTML:00000107 EndHTML:00008499 EndFragment:00008459 EndFragment:00000000 On Error Resume Next
     strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    If Err.number <> 0 Then
         WScript.Echo "Error connecting to: " & strComputer
    For each objInfo in colItems
    dim objDataRow

    Set objDataRow = objDataClass.AddRow

        objDataRow.SetField 0, "Not Applicable"
         objDataRow.SetField 1, "Not Applicable"
         objDataRow.SetField 2, "Not Applicable"
         objDataRow.SetField 3, "Not Applicable"
         objDataRow.SetField 4, "Not Applicable"
         objDataRow.SetField 5, "Not Applicable"
         objDataRow.SetField 6, "Not Applicable"
         objDataRow.SetField 7, "Not Applicable"


    Next

    set objDataRow = objDataClass.AddRow

    WScript.Echo objInfo.IsActivated_InitialValue

    WScript.Echo objInfo.IsEnabled_InitialValue

    WScript.Echo objInfo.IsOwned_InitialValue

    WScript.Echo objInfo.ManufacturerId

    WScript.Echo objInfo.ManufacturerVersion

    WScript.Echo objInfo.ManufacturerVersionInfo

    WScript.Echo objInfo.PhysicalPresenceVersionInfo

    WScript.Echo objInfo.SpecVersion

    objDataRow.SetField 0, objInfo.IsActivated_InitialValue

    objDataRow.SetField 1, objInfo.IsEnabled_InitialValue

    objDataRow.SetField 2, objInfo.IsOwned_InitialValue

    objDataRow.SetField 3, objInfo.ManufacturerId

    objDataRow.SetField 4, objInfo.ManufacturerVersion

    objDataRow.SetField 5, objInfo.ManufacturerVersionInfo

    objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo

    objDataRow.SetField 7, objInfo.SpecVersion


    End IF

     



  • 23.  RE: Vb Script Custom Inventory

    Posted Jan 15, 2019 09:14 AM

    Untested, but you are still referencing 'objDataClass' which is unecessary for now and don't use 'objDataRow'.

    You want to create a script that outputs either the wmi call found data or it didn't.

    Don't over complicate for now, get that working first.

    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")
    
    If Err.number <> 0 Then
         WScript.Echo "Error connecting to: " & strComputer
    
         WScript.Echo "Setting Not Applicable when necessary"
    Else
         Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
        If Err.number <> 0 Then
            WScript.Echo "Another Error"
        End If
    
        For each objInfo in colItems
    
            WScript.Echo objInfo.IsActivated_InitialValue
            WScript.Echo objInfo.IsEnabled_InitialValue
            WScript.Echo objInfo.IsOwned_InitialValue
            WScript.Echo objInfo.ManufacturerId
            WScript.Echo objInfo.ManufacturerVersion
            WScript.Echo objInfo.ManufacturerVersionInfo
            WScript.Echo objInfo.PhysicalPresenceVersionInfo
            WScript.Echo objInfo.SpecVersion
        Next
    End If

     



  • 24.  RE: Vb Script Custom Inventory

    Posted Jan 15, 2019 11:16 AM

    ran the above script.  On pc that TPM is on, got the data as I did way back in the beginning.  For the pc where TPM is Disabled, there is no output or message in task status output



  • 25.  RE: Vb Script Custom Inventory

    Posted Jan 16, 2019 03:39 AM

    Can you run the script manually on the machine that isn't working?

    Does it show any errors?



  • 26.  RE: Vb Script Custom Inventory

    Posted Jan 16, 2019 02:38 PM

    Ran the script in vbsedit. Both pcs output 2 popups

    1-error connecting to:.

    2-setting not applicable when necessary.

    However, do not get an error when run as an Altiris task on pc with TPM enabled, and no output on pc where TPM not enabled. When Altiris runs the script the put put is   as seen in attached Enabled.jpg output and the disbaled pc is in attached disabled .jpg



  • 27.  RE: Vb Script Custom Inventory

    Posted Jan 16, 2019 03:15 PM
    Are you running the script as the logged in user manually? But when Altiris runs it’s as who?


  • 28.  RE: Vb Script Custom Inventory

    Posted Jan 17, 2019 07:23 AM

    Your question made me think and re-run manually.  I just ran script in vbs as Admin and  there were no error messages.  PC with TPM showed data in pop ups- same data as in Altiris run script.  PC without TPM, no pop ups, just  completed the script.

    Script running in Altiris is run as Local System Account.



  • 29.  RE: Vb Script Custom Inventory

    Posted Jan 24, 2019 02:54 PM

    Any new ideas?.  Still not resolved



  • 30.  RE: Vb Script Custom Inventory

    Posted Jan 25, 2019 09:30 AM

    When you are testing on the machine are you just double clicking on the vbs or running it via cscript in an elevated cmd?

    I'd try via cmd and see if there are any outputs.

    The only other thing is that "colItems" isn't error-ing and you need to check if it's null and output the N/A instead of looping it



  • 31.  RE: Vb Script Custom Inventory

    Posted Jan 25, 2019 01:37 PM

    I am using Vbsedit.  I run as elevated , the editor opens and I paste in the script.  Then click on 'Start'

    Copied the script above (Jan 15) .  Ran on pc with TPM, get all the values.  Ran on pc without TPM, script ran, no error, no output



  • 32.  RE: Vb Script Custom Inventory

    Posted Jan 25, 2019 03:43 PM
    Can you add back in If colItems.Count > 0 Then WScript.Echo “a” Else WScript.Echo “b” End If


  • 33.  RE: Vb Script Custom Inventory

    Posted Jan 25, 2019 03:44 PM
    Have you tried the inbuilt debugger in vbsedit? You could run the script in debug mode and step through each line one by one and see what each variable is set to. See if colItems actually gets a value etc


  • 34.  RE: Vb Script Custom Inventory

    Posted Jan 28, 2019 10:15 AM

    StackOverflow offered this:

    On Error Resume Next
    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")
    If VarType(TPMProvider) <> 9 Then
        WScript.Echo "TPM not enabled"
    Else
        WScript.Echo TPMProvider.IsActivated_InitialValue
        WScript.Echo TPMProvider.IsEnabled_InitialValue
        WScript.Echo TPMProvider.IsOwned_InitialValue
        WScript.Echo TPMProvider.ManufacturerId
        WScript.Echo TPMProvider.ManufacturerVersion
        WScript.Echo TPMProvider.ManufacturerVersionInfo
        WScript.Echo TPMProvider.PhysicalPresenceVersionInfo
        WScript.Echo TPMProvider.SpecVersion
    End If

    This runs and in the Altiris task output I either get the "TPM not enabled" or the actual values  ( as in the original script that started this post.  I do not know how or where to put the StackOverflow piece into the Altiris script so that the  "TPM not enabled" is written to "objDataRow.SetField 0, objInfo.IsActivated_InitialValue"  where the actual value would be entered from a pc where TPM is  Enabled.



  • 35.  RE: Vb Script Custom Inventory

    Posted Jan 28, 2019 12:29 PM

    Something like

    Dim objDataRow
    Set objDataRow = objDataClass.AddRow
    
    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")
    
    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
        For each objInfo in colItems
            objDataRow.SetField 0, objInfo.IsActivated_InitialValue
            objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
            objDataRow.SetField 2, objInfo.IsOwned_InitialValue
            objDataRow.SetField 3, objInfo.ManufacturerId
            objDataRow.SetField 4, objInfo.ManufacturerVersion
            objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
            objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
            objDataRow.SetField 7, objInfo.SpecVersion
        Next
    End If

     



  • 36.  RE: Vb Script Custom Inventory

    Posted Jan 28, 2019 12:32 PM

    Prob best to loop "colItems" like before



  • 37.  RE: Vb Script Custom Inventory

    Posted Jan 28, 2019 12:59 PM

    I removed lines from the original script relating to colitems- this is what I tried to run  including your last post:


    '===================================================================================================================


    '===================================================================================================================

     

     

    strComputer = "."

     

                                           

     
     
    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

     

     

     

    Dim objDataRow
    Set objDataRow = objDataClass.AddRow

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
        objDataRow.SetField 0, objInfo.IsActivated_InitialValue
        objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
        objDataRow.SetField 2, objInfo.IsOwned_InitialValue
        objDataRow.SetField 3, objInfo.ManufacturerId
        objDataRow.SetField 4, objInfo.ManufacturerVersion
        objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
        objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
        objDataRow.SetField 7, objInfo.SpecVersion
    End If


     

    nse.SendQueued

     

    '===================================================================================================================

     

     

     

    '===================================================================================================================

    On the pc that has TPM, there is an error:C:\windows\TEMP\AltirisScriptA9DB508010F46E5837.vbs(68, 5) Microsoft VBScript runtime error: Object required: 'objWMIService'

    On the pc without TPM: C:\windows\TEMP\AltirisScriptAE456B008C5F1EED.vbs(55, 19) (null): 0x80041002

     



  • 38.  RE: Vb Script Custom Inventory

    Posted Jan 28, 2019 01:22 PM

    I believe I have it working: Will test against a few more pcs now.  Will let you know.  Meanwhile, thanks for your continual help with this- I probably frustrated you quite a bit.


    '===================================================================================================================

     

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

                                           

     
     
    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

     

    For each objInfo in colItems

     

     
    Dim objDataRow
    Set objDataRow = objDataClass.AddRow

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
        objDataRow.SetField 0, objInfo.IsActivated_InitialValue
        objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
        objDataRow.SetField 2, objInfo.IsOwned_InitialValue
        objDataRow.SetField 3, objInfo.ManufacturerId
        objDataRow.SetField 4, objInfo.ManufacturerVersion
        objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
        objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
        objDataRow.SetField 7, objInfo.SpecVersion
    End If
     


    nse.SendQueued

     
    Next
    '===================================================================================================================



  • 39.  RE: Vb Script Custom Inventory

    Posted Jan 28, 2019 01:27 PM

    Happy to help, I just wished I had a machine I could test both scenarios on, or we prob would have fixed it sooner.

    Hope the testing goes well.



  • 40.  RE: Vb Script Custom Inventory

    Posted Jan 31, 2019 10:56 AM

    Apparently what I ran when I stated it was working was not actually 'working' 

    I do not have any pc that shows 'Not Applicable' in any  row in the db.  Have run the above (both in Altiris and vbesedit) against the same two test pcs and the one with TPM not enabled does not show 'Not Applicable'. 

    However, this part of the script runs and outputs "TPM not enabled" when run in vbsedit:

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"

     Running the whole script in vbsedit/Altiris does not also output "TPM not enabled" .  There is no output at all.



  • 41.  RE: Vb Script Custom Inventory

    Posted Jan 31, 2019 11:18 AM

    Can you capture the event from the client and see what is being sent up

    How to gather Inventory NSEs from client?
    https://support.symantec.com/en_US/article.HOWTO32482.html

    Trapping NSEs on a Windows client
    https://support.symantec.com/en_US/article.HOWTO4191.html



  • 42.  RE: Vb Script Custom Inventory

    Posted Jan 31, 2019 12:37 PM

    I'd expect to see something similar too

    • NSE-FFF-00000037-00000002.ok_.txt
    <row c1="##" c3="True" c4="False" c5="False" c9="Dell Precision M#" c10="Dell Inc." c11="Dell Precision M#" c12="NotInstalled" c13="" hash="###"/>

    With the corresponding values from the data you're trying to get from the wmi call

    i.e.

    objDataRow.SetField 0, objInfo.IsActivated_InitialValue
    <row c1="VALUE">


  • 43.  RE: Vb Script Custom Inventory

    Posted Jan 31, 2019 12:54 PM

    Followed Trapping NSEs. Rebooted after making registry change.  Ran the script to collect TPM info.  There are 4 files in the folder I created. I do not see anything mentionning "Working Final TPM Script" ( name of the task to run script). Is there something 'else' I should be looking for?

    Attached files, renamed .txt in order to upload



  • 44.  RE: Vb Script Custom Inventory

    Posted Jan 31, 2019 01:49 PM

    I took part of the Altiris script  and created a new task>script to test if part of it was working or not. On the pc with no TPM , it did "save the ouput with the task":

    <nobr>Script: </nobr> Microsoft (R) Windows Script Host Version 5.812
    Copyright (C) Microsoft Corporation. All rights reserved.

    TPM not enabled

    On Error Resume Next
    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")
    If VarType(TPMProvider) <> 9 Then
        WScript.Echo "TPM not enabled"
    Else
        WScript.Echo TPMProvider.IsActivated_InitialValue
        WScript.Echo TPMProvider.IsEnabled_InitialValue
        WScript.Echo TPMProvider.IsOwned_InitialValue
        WScript.Echo TPMProvider.ManufacturerId
        WScript.Echo TPMProvider.ManufacturerVersion
        WScript.Echo TPMProvider.ManufacturerVersionInfo
        WScript.Echo TPMProvider.PhysicalPresenceVersionInfo
        WScript.Echo TPMProvider.SpecVersion
    End If

     I do not understand then why in the complete script, it does not output this.



  • 45.  RE: Vb Script Custom Inventory

    Posted Jan 31, 2019 04:04 PM
    There might be other things in the script that are causing errors and stopping the script before it gets to this bit Also in the Else you’re not actually calling your WMI query Maybe it’s just been missed in copying bits to here. I’d start with a simple if else Check on an good and a bad computer, see if it works locally If it does, add it to a task, try again. If it works, add more to the script, test locally, test in a script Repeat.


  • 46.  RE: Vb Script Custom Inventory

    Posted Feb 04, 2019 11:50 AM

      When this part is executed, both pcs have 'results' in the task status output. One shows TPM not enabled, and the other shows the values. When this is in the complete script, neither show any results in the task status output screen.

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")
    If VarType(TPMProvider) <> 9 Then
        WScript.Echo "TPM not enabled"
    Else
        WScript.Echo TPMProvider.IsActivated_InitialValue
        WScript.Echo TPMProvider.IsEnabled_InitialValue
        WScript.Echo TPMProvider.IsOwned_InitialValue
        WScript.Echo TPMProvider.ManufacturerId
        WScript.Echo TPMProvider.ManufacturerVersion
        WScript.Echo TPMProvider.ManufacturerVersionInfo
        WScript.Echo TPMProvider.PhysicalPresenceVersionInfo
        WScript.Echo TPMProvider.SpecVersion
    End If

    The complete script which(incorporating the above 'working' piece) does send the values for the TPM enabled pc and null for the other- still not the correct 'Not Applicable' to the fields 1-7.

    *****************************


    '===================================================================================================================

     

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

                                           

     
     
    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

     

     

     

     
    Dim objDataRow
    Set objDataRow = objDataClass.AddRow

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    WScript.Echo TPMProvider.IsActivated_InitialValue
        WScript.Echo TPMProvider.IsEnabled_InitialValue
        WScript.Echo TPMProvider.IsOwned_InitialValue
        WScript.Echo TPMProvider.ManufacturerId
        WScript.Echo TPMProvider.ManufacturerVersion
        WScript.Echo TPMProvider.ManufacturerVersionInfo
        WScript.Echo TPMProvider.PhysicalPresenceVersionInfo
        WScript.Echo TPMProvider.SpecVersion

        objDataRow.SetField 0, objInfo.IsActivated_InitialValue
        objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
        objDataRow.SetField 2, objInfo.IsOwned_InitialValue
        objDataRow.SetField 3, objInfo.ManufacturerId
        objDataRow.SetField 4, objInfo.ManufacturerVersion
        objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
        objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
        objDataRow.SetField 7, objInfo.SpecVersion
    End If
     


    nse.SendQueued

     
     
    '===================================================================================================================

     

     



  • 47.  RE: Vb Script Custom Inventory

    Posted Feb 04, 2019 12:00 PM

    Didn't we find out that the first three lines of the overall script caused an issue so they aren't necessary.



  • 48.  RE: Vb Script Custom Inventory

    Posted Feb 04, 2019 02:22 PM

    At this point, I have added, removed, tried pieces of and so on, all of which do not give me the actual data results or TPM not Applicable. I  do not know any longer if what you asked above is part of the issue.  

    Now what I have with the following script is- the pc with TPM not enabled is now showing not enabled in all filelds in the database, and the pc with TPM Enabled is now showing Null. It is the exact opposite of what I had when I posted the first script.

      So from this it seems the part relating to "If VarType(TPMProvider) <> 9 Then.... " is working., but the original part from the first scipt I had is not correctly sending the data, as it is Null, when it used to be the  7 data values. 


    '===================================================================================================================

    ON ERROR Resume Next

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

                                           

     
     
    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

     

     

     

     
    Dim objDataRow
    Set objDataRow = objDataClass.AddRow

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    WScript.Echo TPMProvider.IsActivated_InitialValue
        WScript.Echo TPMProvider.IsEnabled_InitialValue
        WScript.Echo TPMProvider.IsOwned_InitialValue
        WScript.Echo TPMProvider.ManufacturerId
        WScript.Echo TPMProvider.ManufacturerVersion
        WScript.Echo TPMProvider.ManufacturerVersionInfo
        WScript.Echo TPMProvider.PhysicalPresenceVersionInfo
        WScript.Echo TPMProvider.SpecVersion

        objDataRow.SetField 0, objInfo.IsActivated_InitialValue
        objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
        objDataRow.SetField 2, objInfo.IsOwned_InitialValue
        objDataRow.SetField 3, objInfo.ManufacturerId
        objDataRow.SetField 4, objInfo.ManufacturerVersion
        objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
        objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
        objDataRow.SetField 7, objInfo.SpecVersion
    End If
     


    nse.SendQueued

     
     
    '===================================================================================================================



  • 49.  RE: Vb Script Custom Inventory

    Posted Feb 04, 2019 04:19 PM
    What could be the reason it’s returning null? It’s because the thing you are sending to there SMP isn’t there. If you look at the script you are saying use a variable that doesn’t exist For example objDataRow.SetField 7, objInfo.SpecVersion Where is “objInfo” After your Else you have a Set colItems = This returns an array so you need to loop it. For each objInfo in colItems ‘add the set fields Next


  • 50.  RE: Vb Script Custom Inventory

    Posted Feb 04, 2019 04:33 PM
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm”) Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) Or Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@") Set colItems = TPMProvider.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)


  • 51.  RE: Vb Script Custom Inventory

    Posted Feb 05, 2019 07:01 AM

    Alex, again, thnaks.  I think you can see that this is above my understanding as far as how this is to be written.  At one ppoint I was told by  an article fom stack overflow not to loop.  Above  you are saying needs to loop.

    Above you have introduced OR.  Is that part of the vb or is that just an expplanation?

     I am getting all this in bits and pieces and just do not know how to put it all together.

    From the beginning, the script gave my the values for a pc with TPPM on.  No problem.  The issue was to handle a pc without TPM by simply writing something like 'not applicable' to the database so the fields were not null.  At one point in this, the script did write 'not applicable', but now  in doing that , it is also writing null for the pc with TPM turned on- the opposite of  of what it originally did

    I simply can't put  this together. I appreciate the help on this matter, but I feel I am getting nowhere due to my lack of abiltiy to put it together corectly in order. I understand the 'concept' here but it is the  'writing' of it that is preventing me from getting it working.

    My understanding of this is- on a pc without TPM, the query(objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", . . .) does not return a value, so we used:

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then. . ...

    So since it does not exist, just write not applicable to the 7 fileds.  Then if it does exist, the state,ent should go the the else, run the objWMIService.ExecQuery("SELECT * FROM Win32_Tpm",  part of this and get the 7 values and write them.

    In theory I do think I understand what it is doing.

     

     



  • 52.  RE: Vb Script Custom Inventory

    Posted Feb 05, 2019 07:25 AM

    Do you have the link to the StackOverflow question?

    ---

    This was my point in getting the script broken down into individual parts, granted it's gone back and forth and things have changed so it's become a bit of a mess but because things have been added and removed variables have become out of sync.

    Depending on what editor you use if you double click on a variable to highlight it, it should then show you where else in your script it is used, in yourcase if you'd done that you would see that you are asking for information from an object that doesn't exist so it wouldn't return any values to your SMP.

    My previous OR comment was to explain this, we originally had a variable called "objWMIService" it was changed to "TPMProvider" but then the original was still trying to be used when it couldn't.

    You need to break the process up into steps, away from the script to understand what is going on.

    You need to "Get" the object from WMI first, then if it's valid "Query" it for the information you need. The query could return multiple rows of data, the Query returns a collection, hence the looping. In your case there should only be one record/row but accessing a single row from a collection needs to be done in a loop or by an index. (colItems[0]).

    I've added some extra notes, this is untested but should hopefully work.

    On Error Resume Next
    
    
    'Create instance of Altiris NSE component
    dim nse
    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")
    ' Set the header data of the NSE
    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
    nse.Priority = 1
    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server
    dim objDCInstance
    'Modify this class guid to match the one generated when you create the custom data class
    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")
    
    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)
    
    Dim objDataRow
    Set objDataRow = objDataClass.AddRow
    
    ' This causes a failure on machines where TPM isn't installed. So remove.
    'strComputer = "."
    'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")
    'Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")
    
    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        'This was originally "objWMIService" but instead use "TPMProvider"
        Set colItems = TPMProvider.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
        
        For each objInfo in colItems
            ' You can't get info from TPMProvider as you use that to execute a Query to retrieve that info.
            objDataRow.SetField 0, objInfo.IsActivated_InitialValue
            objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
            objDataRow.SetField 2, objInfo.IsOwned_InitialValue
            objDataRow.SetField 3, objInfo.ManufacturerId
            objDataRow.SetField 4, objInfo.ManufacturerVersion
            objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
            objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
            objDataRow.SetField 7, objInfo.SpecVersion
        Next
    End If
    
    nse.SendQueued

     



  • 53.  RE: Vb Script Custom Inventory

    Posted Feb 05, 2019 08:13 AM

    One more change after above post and 'EUREKA'!!- it is working.  Thank you for your persistence  with this. Should I post the final script for other's use/reference?



  • 54.  RE: Vb Script Custom Inventory

    Posted Oct 15, 2021 06:11 AM
    YEs please! Now the script is very useful to check the device compatibility with Windws 11. Please share the final script

    Thanks!


  • 55.  RE: Vb Script Custom Inventory

    Posted Feb 05, 2019 08:23 AM

    It would be useful to see the change, thanks.



  • 56.  RE: Vb Script Custom Inventory

    Posted Feb 11, 2019 10:55 AM


    '===================================================================================================================

    ON ERROR Resume Next

     

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftTpm")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

                                           

     
     
    'Create instance of Altiris NSE component

    dim nse

    set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

     

    ' Set the header data of the NSE

    nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"

    nse.Priority = 1

     

    'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server

    dim objDCInstance

    'Modify this class guid to match the one generated when you create the custom data class

    set objDCInstance = nse.AddDataClass ("{fb2182e6-f2db-4c62-8d0f-190dca8723c5}")

     

    dim objDataClass

    set objDataClass = nse.AddDataBlock (objDCInstance)

     

     

     

     
    Dim objDataRow
    Set objDataRow = objDataClass.AddRow

    Dim TPMProvider : Set TPMProvider = GetObject("winmgmts:\\.\root\cimv2\Security\MicrosoftTpm:Win32_Tpm=@")

    If VarType(TPMProvider) <> 9 Then
        'WScript.Echo "TPM not enabled"
        objDataRow.SetField 0, "Not Applicable"
        objDataRow.SetField 1, "Not Applicable"
        objDataRow.SetField 2, "Not Applicable"
        objDataRow.SetField 3, "Not Applicable"
        objDataRow.SetField 4, "Not Applicable"
        objDataRow.SetField 5, "Not Applicable"
        objDataRow.SetField 6, "Not Applicable"
        objDataRow.SetField 7, "Not Applicable"
    Else
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Tpm", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
    For each objInfo in colItems
    WScript.Echo TPMProvider.IsActivated_InitialValue
        WScript.Echo TPMProvider.IsEnabled_InitialValue
        WScript.Echo TPMProvider.IsOwned_InitialValue
        WScript.Echo TPMProvider.ManufacturerId
        WScript.Echo TPMProvider.ManufacturerVersion
        WScript.Echo TPMProvider.ManufacturerVersionInfo
        WScript.Echo TPMProvider.PhysicalPresenceVersionInfo
        WScript.Echo TPMProvider.SpecVersion

        objDataRow.SetField 0, objInfo.IsActivated_InitialValue
        objDataRow.SetField 1, objInfo.IsEnabled_InitialValue
        objDataRow.SetField 2, objInfo.IsOwned_InitialValue
        objDataRow.SetField 3, objInfo.ManufacturerId
        objDataRow.SetField 4, objInfo.ManufacturerVersion
        objDataRow.SetField 5, objInfo.ManufacturerVersionInfo
        objDataRow.SetField 6, objInfo.PhysicalPresenceVersionInfo
        objDataRow.SetField 7, objInfo.SpecVersion
    NEXT
    End If
     


    nse.SendQueued

     
     
    '===================================================================================================================



  • 57.  RE: Vb Script Custom Inventory

    Posted Feb 11, 2019 12:51 PM
    If you’re happy it’s working now are you ok to Mark as solution so the thread closes Thanks