Skip to content

Commit ee1c3dd

Browse files
pl4ntymjr4077au
authored andcommitted
Rename ADTRegSvr32 -PerUser to -AsUser, remove redundant user/context guards
Signed-off-by: Tom Plant <tom.plant@devicie.com>
1 parent 81e35bf commit ee1c3dd

3 files changed

Lines changed: 12 additions & 23 deletions

File tree

src/PSAppDeployToolkit/Public/Invoke-ADTRegSvr32.ps1

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Invoke-ADTRegSvr32
1919
.PARAMETER Action
2020
Specify whether to register or unregister the DLL.
2121
22-
.PARAMETER PerUser
22+
.PARAMETER AsUser
2323
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.
2424
2525
.INPUTS
@@ -43,7 +43,7 @@ function Invoke-ADTRegSvr32
4343
Unregisters the specified DLL file.
4444
4545
.EXAMPLE
46-
Invoke-ADTRegSvr32 -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -Action 'Register' -PerUser
46+
Invoke-ADTRegSvr32 -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -Action 'Register' -AsUser
4747
4848
Registers the specified DLL file for the currently logged on user only.
4949
@@ -83,7 +83,7 @@ function Invoke-ADTRegSvr32
8383
[System.String]$Action,
8484

8585
[Parameter(Mandatory = $false)]
86-
[System.Management.Automation.SwitchParameter]$PerUser
86+
[System.Management.Automation.SwitchParameter]$AsUser
8787
)
8888

8989
begin
@@ -94,12 +94,12 @@ function Invoke-ADTRegSvr32
9494
{
9595
Register
9696
{
97-
"/s$(if ($PerUser) { ' /n /i:user' }) `"$FilePath`""
97+
"/s$(if ($AsUser) { ' /n /i:user' }) `"$FilePath`""
9898
break
9999
}
100100
Unregister
101101
{
102-
"/s /u$(if ($PerUser) { ' /n /i:user' }) `"$FilePath`""
102+
"/s /u$(if ($AsUser) { ' /n /i:user' }) `"$FilePath`""
103103
break
104104
}
105105
}
@@ -166,19 +166,8 @@ function Invoke-ADTRegSvr32
166166

167167
# Register the DLL file and measure the success. Per-user registration writes to the
168168
# user's HKCU hive, so when running as SYSTEM, execute as the logged on user instead.
169-
if ($PerUser -and [PSADT.AccountManagement.AccountUtilities]::CallerSid.IsWellKnown([System.Security.Principal.WellKnownSidType]::LocalSystemSid))
169+
if ($AsUser)
170170
{
171-
if (!(Get-ADTClientServerUser))
172-
{
173-
$naerParams = @{
174-
Exception = [System.InvalidOperationException]::new("The DLL file [$FilePath] cannot be $($Action.ToLowerInvariant() + 'ed') per-user as there is no logged on user to process the request against.")
175-
Category = [System.Management.Automation.ErrorCategory]::InvalidOperation
176-
ErrorId = 'NoActiveUserError'
177-
TargetObject = $FilePath
178-
RecommendedAction = "Please ensure a user is logged onto the system and try again."
179-
}
180-
throw (New-ADTErrorRecord @naerParams)
181-
}
182171
Start-ADTProcessAsUser -FilePath $RegSvr32Path -ArgumentList $ActionParameters -CreateNoWindow -SuccessExitCodes 0
183172
}
184173
else

src/PSAppDeployToolkit/Public/Register-ADTDll.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Register-ADTDll
1616
.PARAMETER FilePath
1717
Path to the DLL file.
1818
19-
.PARAMETER PerUser
19+
.PARAMETER AsUser
2020
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.
2121
2222
.INPUTS
@@ -35,7 +35,7 @@ function Register-ADTDll
3535
Registers the specified DLL file.
3636
3737
.EXAMPLE
38-
Register-ADTDll -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -PerUser
38+
Register-ADTDll -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -AsUser
3939
4040
Registers the specified DLL file for the currently logged on user only.
4141
@@ -70,7 +70,7 @@ function Register-ADTDll
7070
[System.String]$FilePath,
7171

7272
[Parameter(Mandatory = $false)]
73-
[System.Management.Automation.SwitchParameter]$PerUser
73+
[System.Management.Automation.SwitchParameter]$AsUser
7474
)
7575

7676
begin

src/PSAppDeployToolkit/Public/Unregister-ADTDll.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Unregister-ADTDll
1616
.PARAMETER FilePath
1717
Path to the DLL file.
1818
19-
.PARAMETER PerUser
19+
.PARAMETER AsUser
2020
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.
2121
2222
.INPUTS
@@ -35,7 +35,7 @@ function Unregister-ADTDll
3535
Unregisters the specified DLL file.
3636
3737
.EXAMPLE
38-
Unregister-ADTDll -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -PerUser
38+
Unregister-ADTDll -FilePath "C:\Test\DcTLSFileToDMSComp.dll" -AsUser
3939
4040
Unregisters the specified DLL file for the currently logged on user only.
4141
@@ -70,7 +70,7 @@ function Unregister-ADTDll
7070
[System.String]$FilePath,
7171

7272
[Parameter(Mandatory = $false)]
73-
[System.Management.Automation.SwitchParameter]$PerUser
73+
[System.Management.Automation.SwitchParameter]$AsUser
7474
)
7575

7676
begin

0 commit comments

Comments
 (0)