Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/PSAppDeployToolkit/Public/Invoke-ADTRegSvr32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function Invoke-ADTRegSvr32
.PARAMETER Action
Specify whether to register or unregister the DLL.

.PARAMETER AsUser
Specifies that the DLL should be registered for the current user only by calling its DllInstall entry point with the 'user' argument (regsvr32.exe /n /i:user). If this function is running under the SYSTEM account, regsvr32.exe is executed in the context of the currently logged on user. Note that the DLL must support per-user registration via a DllInstall export for this to work.

.INPUTS
None

Expand All @@ -39,6 +42,11 @@ function Invoke-ADTRegSvr32

Unregisters the specified DLL file.

.EXAMPLE
Invoke-ADTRegSvr32 -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -Action 'Register' -AsUser

Registers the specified DLL file for the currently logged on user only.

.NOTES
An active ADT session is NOT required to use this function.

Expand Down Expand Up @@ -72,7 +80,10 @@ function Invoke-ADTRegSvr32

[Parameter(Mandatory = $true)]
[ValidateSet('Register', 'Unregister')]
[System.String]$Action
[System.String]$Action,

[Parameter(Mandatory = $false)]
[System.Management.Automation.SwitchParameter]$AsUser
)

begin
Expand All @@ -83,12 +94,12 @@ function Invoke-ADTRegSvr32
{
Register
{
"/s `"$FilePath`""
"/s$(if ($AsUser) { ' /n /i:user' }) `"$FilePath`""
break
}
Unregister
{
"/s /u `"$FilePath`""
"/s /u$(if ($AsUser) { ' /n /i:user' }) `"$FilePath`""
break
}
}
Expand Down Expand Up @@ -153,8 +164,16 @@ function Invoke-ADTRegSvr32
throw (New-ADTErrorRecord @naerParams)
}

# Register the DLL file and measure the success.
Start-ADTProcess -FilePath $RegSvr32Path -ArgumentList $ActionParameters -CreateNoWindow -SuccessExitCodes 0
# Register the DLL file and measure the success. Per-user registration writes to the
# user's HKCU hive, so when running as SYSTEM, execute as the logged on user instead.
if ($AsUser)
{
Start-ADTProcessAsUser -FilePath $RegSvr32Path -ArgumentList $ActionParameters -CreateNoWindow -SuccessExitCodes 0
}
else
{
Start-ADTProcess -FilePath $RegSvr32Path -ArgumentList $ActionParameters -CreateNoWindow -SuccessExitCodes 0
}
}
catch
{
Expand Down
13 changes: 12 additions & 1 deletion src/PSAppDeployToolkit/Public/Register-ADTDll.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function Register-ADTDll
.PARAMETER FilePath
Path to the DLL file.

.PARAMETER AsUser
Specifies that the DLL should be registered for the current user only by calling its DllInstall entry point with the 'user' argument (regsvr32.exe /n /i:user). If this function is running under the SYSTEM account, regsvr32.exe is executed in the context of the currently logged on user. Note that the DLL must support per-user registration via a DllInstall export for this to work.

.INPUTS
None

Expand All @@ -31,6 +34,11 @@ function Register-ADTDll

Registers the specified DLL file.

.EXAMPLE
Register-ADTDll -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -AsUser

Registers the specified DLL file for the currently logged on user only.

.NOTES
An active ADT session is NOT required to use this function.

Expand Down Expand Up @@ -59,7 +67,10 @@ function Register-ADTDll
}
return ![System.String]::IsNullOrWhiteSpace($_)
})]
[System.String]$FilePath
[System.String]$FilePath,

[Parameter(Mandatory = $false)]
[System.Management.Automation.SwitchParameter]$AsUser
)

begin
Expand Down
13 changes: 12 additions & 1 deletion src/PSAppDeployToolkit/Public/Unregister-ADTDll.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function Unregister-ADTDll
.PARAMETER FilePath
Path to the DLL file.

.PARAMETER AsUser
Specifies that the DLL should be unregistered for the current user only by calling its DllInstall entry point with the 'user' argument (regsvr32.exe /u /n /i:user). If this function is running under the SYSTEM account, regsvr32.exe is executed in the context of the currently logged on user. Note that the DLL must support per-user registration via a DllInstall export for this to work.

.INPUTS
None

Expand All @@ -31,6 +34,11 @@ function Unregister-ADTDll

Unregisters the specified DLL file.

.EXAMPLE
Unregister-ADTDll -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -AsUser

Unregisters the specified DLL file for the currently logged on user only.

.NOTES
An active ADT session is NOT required to use this function.

Expand Down Expand Up @@ -59,7 +67,10 @@ function Unregister-ADTDll
}
return ![System.String]::IsNullOrWhiteSpace($_)
})]
[System.String]$FilePath
[System.String]$FilePath,

[Parameter(Mandatory = $false)]
[System.Management.Automation.SwitchParameter]$AsUser
)

begin
Expand Down