Scheduled task wrong UserId #28

Closed
opened 2023-09-30 18:49:16 +00:00 by NightFuture · 1 comment
NightFuture commented 2023-09-30 18:49:16 +00:00 (Migrated from codeberg.org)

Your powershell script for creating auto update task doesn't work on my system. When i run i get this:

Register-ScheduledTask : The parameter is incorrect.
(23,8):UserId:
C:\Users\Sandor\AppData\Roaming\librewolf\WinUpdater\ScheduledTask-Create.ps1:21 char:1
+ Register-ScheduledTask -TaskName "$Title ($UserName)" -Action $Action ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule
   dTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask

Solved this problem with changing ScheduledTask-Create.ps1 like this:

...
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
  Write-Output "Requesting administrator privileges"
  $User = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
  $UserName = [Environment]::UserName
  $Script = $MyInvocation.MyCommand.Path
  Start-Process powershell.exe -Verb RunAs "-ExecutionPolicy RemoteSigned -File `"$PSCommandPath`" `"${User}`" `"${UserName}`""
  Exit
}

...
$User     = If ($Args[0]) {$Args[0]} Else {[System.Security.Principal.WindowsIdentity]::GetCurrent().Name}
$UserName = If ($Args[1]) {$Args[1]} Else {[Environment]::UserName}
Register-ScheduledTask -TaskName "$Title ($UserName)" -Action $Action -Settings $Settings -Trigger $4Hours,$AtLogon -User $User -RunLevel Highest -Force
...
Your powershell script for creating auto update task doesn't work on my system. When i run i get this: ``` Register-ScheduledTask : The parameter is incorrect. (23,8):UserId: C:\Users\Sandor\AppData\Roaming\librewolf\WinUpdater\ScheduledTask-Create.ps1:21 char:1 + Register-ScheduledTask -TaskName "$Title ($UserName)" -Action $Action ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule dTask], CimException + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask ``` Solved this problem with changing ScheduledTask-Create.ps1 like this: ``` ... If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Output "Requesting administrator privileges" $User = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $UserName = [Environment]::UserName $Script = $MyInvocation.MyCommand.Path Start-Process powershell.exe -Verb RunAs "-ExecutionPolicy RemoteSigned -File `"$PSCommandPath`" `"${User}`" `"${UserName}`"" Exit } ... $User = If ($Args[0]) {$Args[0]} Else {[System.Security.Principal.WindowsIdentity]::GetCurrent().Name} $UserName = If ($Args[1]) {$Args[1]} Else {[Environment]::UserName} Register-ScheduledTask -TaskName "$Title ($UserName)" -Action $Action -Settings $Settings -Trigger $4Hours,$AtLogon -User $User -RunLevel Highest -Force ... ```
ltguillaume commented 2023-09-30 19:38:16 +00:00 (Migrated from codeberg.org)

Thanks for reporting this and providing a solution 😃 I've committed your changes in f97849216e. I'd been testing this with a lot of different characters in usernames and with some different domain situations, but apparently there's something I missed.

Would you perhaps know what could cause this? Do you have some specific domain settings, or do you use an online Microsoft account perhaps?

Thanks for reporting this _and_ providing a solution 😃 I've committed your changes in f97849216e9f04ed5263f1de7d010bfd1de00683. I'd been testing this with a lot of different characters in usernames and with some different domain situations, but apparently there's something I missed. Would you perhaps know what could cause this? Do you have some specific domain settings, or do you use an online Microsoft account perhaps?
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
librewolf/winupdater#28
No description provided.