Skip to content
Menu
ScriptingNerd
  • Home
  • Quick Tips
  • GitHub
ScriptingNerd

Use Powershell to create a "fake" program in the programs and features list for indexing purposes

Posted on March 13, 2020February 2, 2023 by Patrik

For a reason I won't go in to here I recently had to create a fake program in the programs and features list of a computer. One example when this might be useful is for indexing purposes but there are other usecases for it as well.

Since this list is saved in the registry adding a new program to it is easy. I tend to follow the "code should document itself" approach since I never know who might have to modify my code at a later date, to that end I decided to make a function out of this instead of adding a lot of stuff to the registry inside the main script.

If you find another usecase for this script I would be happy to hear it.

Picture of appwiz with a fake program
Function New-PopsFakeProgram {
    <#
    .SYNOPSIS
        Add a fake program to programs & features
    .DESCRIPTION
        Add a fake program to programs & features
    .PARAMETER Name
        The internal name
    .PARAMETER DisplayName
        The name that should be shown
    .PARAMETER Publisher
        The name of the publisher
    .PARAMETER DisplayVersion
        The version number
    .PARAMETER DisplayIcon
       Path to a display icon, can be an exe file
    .PARAMETER UninstallString
        The string for uninstalling the program
    .PARAMETER NoRemove
        Remove Uninstall option in appwiz
    .PARAMETER NoModify
        Remove Modify option in appwiz
    .EXAMPLE
        New-PopsFakeProgram -Name "MyFakeProgram" -DisplayName "My fake program"
    .NOTES
    .LINK
        scriptingnerd.com/2020/03/13/use-powershell-to-create-a-fake-program-in-the-programs-and-features-list-for-indexing-purposes
    #>
    
    Param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [string]$Name,
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [string]$DisplayName,
        [Parameter(Mandatory = $false)]
        [ValidateNotNullorEmpty()]
        [string]$Publisher = "Dummy",
        [Parameter(Mandatory = $false)]
        [ValidateNotNullorEmpty()]
        [string]$DisplayVersion = $(Get-Date -Format "yyyy.dd.MM.HHmm"),
        [Parameter(Mandatory = $false)]
        [ValidateNotNullorEmpty()]
        [string]$DisplayIcon = "C:\Windows\explorer.exe",
        [Parameter(Mandatory = $false)]
        [ValidateNotNullorEmpty()]
        [string]$UninstallString = "DummyUninstall",
        [Parameter(Mandatory = $false)]
        [ValidateNotNullorEmpty()]
        [switch]$NoRemove,
        [Parameter(Mandatory = $false)]
        [ValidateNotNullorEmpty()]
        [switch]$NoModify
    )
    
    if ( -not (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -PathType Container) ) {
        New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Name $Name | Out-Null
    }

    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "DisplayName" -Type String -Value $DisplayName -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "Publisher" -Type String -Value $Publisher -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "DisplayVersion" -Type String -Value $DisplayVersion -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "DisplayIcon" -Type String -Value $DisplayIcon -Force | Out-Null
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "UninstallString" -Type String -Value $UninstallString -Force | Out-Null
    
    If ($NoRemove) {
        New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "NoRemove" -Type Dword -Value 1 -Force | Out-Null
    }

    If ($NoModify) {
        New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Name "NoModify" -Type Dword -Value 1 -Force | Out-Null
    }
}
    
Function Remove-PopsFakeProgram {
    <#
    .SYNOPSIS
        Remove a program from programs & features
    .DESCRIPTION
        Remove a program from programs & features
    .PARAMETER Name
        The internal name, this is probably not the one you see in programs & features
    .EXAMPLE
        Remove-PopsFakeProgram -Name "MyFakeProgram"
    .NOTES
    .LINK
        scriptingnerd.com/2020/03/13/use-powershell-to-create-a-fake-program-in-the-programs-and-features-list-for-indexing-purposes
    #>
    Param(
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [string]$Name
    )
    if ( Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -PathType Container ) {
        Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$Name" -Recurse -Force  
    }
        
}

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Patrik Johansson
    Senior System Administrator

    Working with a wide flora of systems but with a focus on Configuration Manager (MEMCM/SCCM).

    Passionate about Powershell and building tools that are easy to use for everyone.
    In my spare time I work on other coding projects as well, mainly Booksonic

    LinkedIn GitHub Blog

Recent Posts

  • How to download CMTrace from Microsoft
  • Powershell counting to $null instead of 1
  • Running ForEach in parallel on Windows Powershell 5 (and older)
  • Use Powershell to create a "fake" program in the programs and features list for indexing purposes
  • How to read the manifest of an appx package file using Powershell

Archives

  • February 2023
  • April 2022
  • November 2021
  • March 2020
  • December 2019
  • February 2019

Categories

  • Powershell
  • Quick Tips
  • Below are affiliate links, if you click on them and buy something I may earn a small amount of money without any additional cost to you. Any links found here are for products I am using myself and can vouch for.
  • InterServer
    Very cheap SSD/HDD based virtual servers (VPS). Starting at $6/month for 1TB. Use coupon code BOOKSONIC and get the first month for just 1 cent. I have recently started using intersever for personal projects and so far I am very happy with them.
  • Contabo
    Cheap HDD/SSD/NVMe based Virtual servers (VPS)
    I have used Contabo for years both for my private needs as well as to host the booksonic demo server
©2023 ScriptingNerd | Powered by WordPress & Superb Themes