Select Page

Credit to Jörgen Nilsson for the original post but this didn’t quite meet my need as we absolutely abhor using ActiveSetup actions in our environment — instead what we do is add a profile parse to grab the existing profiles and mount the Registry for the user and insert the Registry key (obviously if it fails then it’s the local user logged on and then we just add the Registry key directly).  Here’s the revised code:

# Script to associate .log and .lo_ files to CMtrace and make it the default log reader
# Version 1.1 (11/30/2018)
# Chris Lewis -- https://desktopmgmt.com
#
# Original source code credit to: Jörgen Nilsson - CCMexec.com

# The modification you'll need to make is on line 37 where you'll use the full path to the CMTrace app on your system

# Set default ErrorActionPreference

cls
Write-Host `n
Write-Host "### ### ### ### ### ### ### ### ### ### ### ### ### ### ###" 
Write-Host "###                                                     ###" 
Write-Host "### Registering CMTrace as the default Log file reader  ###" 
Write-Host "###                                                     ###" 
Write-Host "### ### ### ### ### ### ### ### ### ### ### ### ### ### ###" `n

$ErrorActionPreference = "SilentlyContinue"

try {

# Create the Registry keys

New-Item -Path 'HKLM:\Software\Classes\.lo_' -type Directory -Force | Out-Null
New-Item -Path 'HKLM:\Software\Classes\.log' -type Directory -Force | Out-Null 
New-Item -Path 'HKLM:\Software\Classes\.log.File' -type Directory -Force | Out-Null 
New-Item -Path 'HKLM:\Software\Classes\.Log.File\shell' -type Directory -Force | Out-Null 
New-Item -Path 'HKLM:\Software\Classes\Log.File\shell\Open' -type Directory -Force | Out-Null 
New-Item -Path 'HKLM:\Software\Classes\Log.File\shell\Open\Command' -type Directory -Force | Out-Null 
New-Item -Path 'HKLM:\Software\Microsoft\Trace32' -type Directory -Force | Out-Null 

# Create the properties to make CMtrace the default log viewer

New-ItemProperty -LiteralPath 'HKLM:\Software\Classes\.lo_' -Name '(default)' -Value "Log.File" -PropertyType String -Force | Out-Null 
New-ItemProperty -LiteralPath 'HKLM:\Software\Classes\.log' -Name '(default)' -Value "Log.File" -PropertyType String -Force | Out-Null
New-ItemProperty -LiteralPath 'HKLM:\Software\Classes\Log.File\shell\open\command' -Name '(default)' -Value "`"C:\Windows\System32\CMTraceX64.exe`" `"%1`"" -PropertyType String -Force | Out-Null

Write-Host "Successfully configured HKLM:\Software\Classes for file types and Open command" `n

}

catch {

Write-host "Unable to update the Registry. :( Sorry " `n

}

# Create an ActiveSetup that will remove the initial question in CMtrace if it should be the default reader
# New-Item -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\CMtrace" -type Directory
# new-itemproperty "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\CMtrace" -Name "Version" -Value 1 -PropertyType String -Force 
# new-itemproperty "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\CMtrace" -Name "StubPath" -Value "reg.exe add HKCU\Software\Microsoft\Trace32 /v ""Register File Types"" /d 0 /f" -PropertyType ExpandString -Force 

# Create array of all non-special user profiles

$Profiles = gwmi -Class Win32_UserProfile -Filter ("Special = False") ;

# Manipulate the array to mount the local registry and insert value
# Inserts registry key for all existing (non-special) profile users

Foreach ($Profile in $Profiles) {

    $ProPath = $Profile.LocalPath

    # Check whether user is currently logged-on user and, if so, just add Registry entry directly

    If ($ProPath -eq $env:USERPROFILE) { 

        Write-Host "Modifying the registry for the logged on user" `n
        reg.exe add HKCU\Software\Microsoft\Trace32 /v "Register File Types" /d 0 /f | Out-Null

    }

    else { 
    
        Write-host "Modifying user profile: $ProPath"
        & reg.exe load HKLM\DefUser $ProPath\NTUser.dat | Out-Null
        & reg.exe add HKLM\DefUser\Software\Microsoft\Trace32 /v "Register File Types" /d 0 /f | Out-Null
        # reg import cmtrace.reg
        & reg.exe unload HKLM\DefUser | Out-Null

    }

}

# Insert registry value for Default user profile (affects all new user logins)

Write-Host "Modifying the Default User profile" `n
& reg.exe load HKLM\DefUser C:\Users\Default\NTUser.dat | Out-Null
& reg.exe add HKLM\DefUser\Software\Microsoft\Trace32 /v "Register File Types" /d 0 /f | Out-Null
# reg import cmtrace.reg
& reg unload HKLM\DefUser | Out-Null
Write-Host "Done" `n

 

The original code was from ccmexec.com