Skip to content

Add -PerUser support to Register-ADTDll, Unregister-ADTDll and Invoke-ADTRegSvr32#3

Closed
Tom Plant (pl4nty) wants to merge 2 commits into
mainfrom
feature/register-dll-as-user
Closed

Add -PerUser support to Register-ADTDll, Unregister-ADTDll and Invoke-ADTRegSvr32#3
Tom Plant (pl4nty) wants to merge 2 commits into
mainfrom
feature/register-dll-as-user

Conversation

@pl4nty

Copy link
Copy Markdown
Member

Pull Request

Description

Adds a -PerUser switch to Register-ADTDll, Unregister-ADTDll and Invoke-ADTRegSvr32 to support per-user COM registration.

The switch appends /n /i:user to the regsvr32.exe arguments, which skips DllRegisterServer and instead calls the DLL's DllInstall entry point with the 'user' argument so registration data is written to HKCU rather than HKLM. This is required for DLLs that support per-user registration (e.g. the Microsoft Teams meeting add-in loader) when deploying without machine-wide registration.

Because deployments typically run as SYSTEM — where HKCU writes would land in SYSTEM's own hive — the function detects a SYSTEM caller and executes regsvr32.exe in the context of the currently logged on user via Start-ADTProcessAsUser, mirroring the existing pattern in Set-ADTActiveSetup. If no user is logged on, a clear NoActiveUserError is thrown rather than silently registering into the wrong hive.

Note: the DLL must export DllInstall with per-user support for this to work; this is documented in the comment-based help.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • General code cleanup (non-breaking change which improves readability)

Checklist

  • I am pulling to the main branch
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have tested my changes to prove my fix is effective
  • I have tested that the module can build following my changes (not run; the module was imported directly from src and all three functions parse and execute — script-only change, no build pipeline impact expected)
  • I have made sure that any script file-encoding is set to UTF8 with BOM, i.e. unchanged.

How Has This Been Tested?

Tested locally on Windows 11 (PowerShell 7.6.3, non-elevated) against Microsoft.Teams.AddinLoader.dll (x64), which supports per-user registration via DllInstall:

  1. Register-ADTDll -FilePath <dll> -PerUser -WhatIf — confirmed no registry changes are made (SupportsShouldProcess honoured).
  2. Register-ADTDll -FilePath <dll> -PerUser — confirmed HKCU\Software\Classes\CLSID\{19A6E644-14E6-4A60-B8D7-DD20610A871D}\InprocServer32 was written pointing at the specified DLL.
  3. Unregister-ADTDll -FilePath <dll> -PerUser — confirmed the HKCU registration was removed.
  4. Verified UTF-8 BOM preserved on all three files and validated with the PowerShell language parser.

The SYSTEM code path (Start-ADTProcessAsUser hand-off) follows the established pattern from Set-ADTActiveSetup but has not been exercised under a SYSTEM session locally.

🤖 Generated with Claude Code

Tom Plant (pl4nty) and others added 2 commits July 4, 2026 19:22
…-ADTRegSvr32.

Adds a -PerUser switch that performs per-user DLL registration via
regsvr32.exe /n /i:user, calling the DLL's DllInstall entry point so
registration data is written to HKCU instead of HKLM. When invoked
under the SYSTEM account, regsvr32.exe is executed in the context of
the currently logged on user via Start-ADTProcessAsUser so the
registration lands in the correct user hive.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… guards

Signed-off-by: Tom Plant <tom.plant@devicie.com>
@mjr4077au Mitch Richters (mjr4077au) deleted the feature/register-dll-as-user branch July 4, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants