IT Management Suite

 View Only

 List of details Uninstall software through Altiris Registry Inventory

Vikas.Dhiman's profile image
Vikas.Dhiman posted Dec 23, 2022 07:40 AM
Can anyone help me to create vbs to get the data from the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

I have the below script but no idea how add this data in custom data class.
I need every registry details under install from every system.

https://morgantechspace.com/2014/04/vbscript-to-get-list-of-installed-software-through-registry.html
WDRAIN1's profile image
WDRAIN1

Question on why would you  pull the same data with a custom inventory that is already contained in the Inv_AddRemoveProgram sql table.

The Inventory PlugIn sub-agent already pulls the data from the vbscript and populates in the Inv_AddRemoveProgram SQL table.

Vikas.Dhiman's profile image
Vikas.Dhiman
Hi WDRAIN1,
Appreciate your reply. I want to uninstall unauthorized  applications and programs from each systems. So i want data from each system that i can create a script for the same. If you have another idea to do it from Altiris Console please let me know.
WDRAIN1's profile image
WDRAIN1

Hi Vikas,

Here's one of few way's to do this..

1) build a filter using a SQL query of the software that you want to remove

2) write and test a script to silently uninstall software that desire to uninstall (my preference is PowerShell)

3) Create a run script Task with the script from step 2

4) Create a SWD policy, create a Delivery Target using the filter in step 1, Add the Task/Job from step 3 , and then schedule the policy execution time.

Roy B's profile image
Broadcom Employee Roy B
You can use the SQL below to create a SQL filter like WDrain1 mentions: 

select c.Guid --, arp.*
from vcomputer c
join Inv_AddRemoveProgram arp
on arp._ResourceGuid = c.Guid
where arp.DisplayName like '%SoftwareName%'    --enter Software Name between %
and InstallFlag = 1

FYI: When Software Inventory is run it brings back the contents of the Uninstall Reg Key, and puts it in the Inv_AddRemoveProgram dataclass.  This also includes the Uninstall string.

If you want to see what's there for a computer:

select * from Inv_AddRemoveProgram arp
join vcomputer c
on c.guid = arp._ResourceGuid
where c.Name = 'ComputerName'   -- enter name of computer
and arp.InstallFlag = 1
Chris Farrell's profile image
Broadcom Employee Chris Farrell
As was mentioned, the data you are looking for is already present provided you have software inventories running. For completeness, here is the documentation on creating the custom data class and examples you can use to fit the vbscript logic into a script that will send the data back to your custom data class - the first link takes you to the KB for creating the custom data class: Popular Custom Inventory Samples (8.x)

Here is a sample script to get computer name, software, and version:

On Error Resume Next
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
Dim objReg, strSubkey, arrSubkeys
Dim Name, Version
strComputer = "."
Set wshShell = WScript.CreateObject( "WScript.Shell" )
ComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

'=====================================================================
'Create instance of Altiris NSE component
dim nse
set nse = WScript.CreateObject ("Altiris.AeXNSEvent")

' Set the header data of the NSE
' This GUID for the NS is the same for all versions of 8.x
nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
nse.Priority = 1

myDataClass = "{PUT CUSTOM DATA CLASS GUID HERE LEAVE BRACKETS AND QUOTES}"

'Create Inventory data block.
dim objDCInstance
set objDCInstance = nse.AddDataClass (myDataClass)

dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)

' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
Dim objDataRow

'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
If Name <> "" Then
     set objDataRow = objDataClass.AddRow
     objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey,"DisplayVersion",Version
     objDataRow.SetField 0, ComputerName
     objDataRow.SetField 1, Name
     objDataRow.SetField 2, Version
End If

Next

'send the NSE file
nse.Send
Vikas.Dhiman's profile image
Vikas.Dhiman
Thanks WDRAIN1 & Roy B,
Appreciate your reply, It is truly help for me but some software having uninstall key ab below line with uninstall.exe. Can you pleas help me how we can run it silently on computers with an example.
"C:\Program Files (x86)\Web Components\unins000.exe"

Again Thanks for the reply.
WDRAIN1's profile image
WDRAIN1

Hi Vikas

In step 3 of my previous post create a run script task of the PowerShell Type and use the below PowerShell script as a template. Substitue the softwarename1 and 2 with your apps that want to remove... Test the script and be sure to configure the Show Script is hidden. This script will be part of the SWD Policy as discussed in my previous post.

$apps = @('softwarename1', 'softwarename2')
$UnInstall = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
$apps | % {
    $app = $_
    $UnInstall | % { 
       GCI $_ -ErrorAction SilentlyContinue | % {  Get-ItemProperty $_.name.Replace('HKEY_LOCAL_MACHINE\','HKLM:\') }  | ? {$_.DisplayName -like "*$($app)*"} | % { 
           write-host "uninstalling $($_.Displayname)" -foreground Yellow
           $msi_guid = if ($_.UninstallString -like '*msiexec*'){"{" + ($_.uninstallstring -split "{")[1]}
           $param = if($_.UninstallString  -like "*msiexec*"){@("/x","$($msi_guid)","/q","REBOOT=ReallySuppress")}elseif($_.UninstallString  -like "*unins000.exe*"){@("/verysilent")}
           $prgm = if($_.UninstallString  -like "*msiexec*"){"msiexec.exe"}elseif($_.UninstallString  -like "*unins000.exe*"){$_.UninstallString}
           $UNINSTALL = Start-Process $prgm -ArgumentList $param  -Wait -NoNewWindow -PassThru
           $UNINSTALL.EXITCODE
       }
    }
}


In Step 1 of my previous post use the follow SQL query (modified version from Roy's post) as a filter for the software(s)  that you desire to remove. This version allow for multiple software. Use this query as your template for your filter and include it in the SWD Policy target. 

select GUID FROM vcomputer vc
join Inv_AddRemoveProgram arp on arp._ResourceGuid = vc.Guid and arp.InstallFlag = 1
where arp.DisplayName in ('softwarename1', 'SoftwareName2')

WDRAIN1's profile image
WDRAIN1

Also just to note the PowerShell script can be tweaked to uninstall just about any software application. For some exe's you might have to do a little google'ing to find the silent install option for the UninstallPath.

Regards