kangyu-california / PersistentWindows

fork of http://www.ninjacrab.com/persistent-windows/ with windows 10 update

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

auto_start_pw.bat doesn't work

jonboy99x1 opened this issue · comments

Hi,
First, thanks for this great utility!
It works great when manually started, but I can't get the autostart batchfile to function. It produces the following error on one of my PCs, despite the same copy working perfectly on another. Both are running updated windows 10, and I'm running the batch file as administrator, or from a dos window with admin privileges. I've tried ver 5.48 and 5.49. Any advice? Thanks!

C:\Windows\system32>powershell -ExecutionPolicy Bypass -File "C:\PersistentWindows5.48\auto_start_pw_aux.ps1"
Register-ScheduledTask : The parameter is incorrect.
(9,22):UserId:x570
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:22 char:1

  • Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $ ...
  •   + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule
     dTask], CimException
      + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask
    
    

Get-ScheduledTask : No MSFT_ScheduledTask objects found with property 'TaskName' equal to
'StartPersistentWindowsx570'. Verify the value of the property and retry.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:24 char:9

  • $task = Get-ScheduledTask -TaskName $taskName
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (StartPersistentWindowsx570:String) [Get-ScheduledTask], CimJobException
    • FullyQualifiedErrorId : CmdletizationQuery_NotFound_TaskName,Get-ScheduledTask

The property 'ExecutionTimeLimit' cannot be found on this object. Verify that the property exists and can be set.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:26 char:1

  • $taskSettings.ExecutionTimeLimit = "PT0S" # disable time limit
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound
    
    

Set-ScheduledTask : Cannot validate argument on parameter 'Settings'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:27 char:49

  • Set-ScheduledTask -TaskName $taskName -Settings $taskSettings
  •                                             ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Set-ScheduledTask], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Set-ScheduledTask

Cannot index into a null array.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:29 char:1

  • $task.Actions[0].Arguments = $arguments
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray
    
    

Set-ScheduledTask : Cannot validate argument on parameter 'TaskPath'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:30 char:49

  • ... et-ScheduledTask -TaskName $taskName -TaskPath $task.TaskPath -Action ...
  •                                                ~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Set-ScheduledTask], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Set-ScheduledTask

The property 'Principal' cannot be found on this object. Verify that the property exists and can be set.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:34 char:1

  • $task.Principal = $principal
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound
    
    

Set-ScheduledTask : Cannot validate argument on parameter 'TaskPath'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At C:\PersistentWindows5.48\auto_start_pw_aux.ps1:35 char:49

  • ... et-ScheduledTask -TaskName $taskName -TaskPath $task.TaskPath -Princi ...
  •                                                ~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Set-ScheduledTask], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Set-ScheduledTask

C:\Windows\system32>pause
Press any key to continue . . .

Several users reported the same error which I have no clue.
Please take a look at https://appuals.com/fix-task-scheduler-error-0x80070057/
and share the root cause as feedback

Thanks. None of those issues apply unfortunately.

two methods to workaround

  1. auto startup alternative (not able to run as admin)
    https://support.microsoft.com/en-us/windows/add-an-app-to-run-automatically-at-startup-in-windows-10-150da165-dcd9-7230-517b-cf3c295d89dd
  2. Manually create task using task scheduler, replicating the task settings using the working PC as reference.

Thanks, I created the task using task scheduler and worked fine. Not sure if there's something about my username that throws a weird bug in the task registration process within powershell. Checked on 2 other PCs and ps script runs perfectly on them too.
I then exported the task from within task scheduler in case it gets deleted somehow on this PC.

There is definitely some weirdness going on here. If I delete the task, then re-import it from the xml file I exported/saved it to, I get:

An error has occurred for task. Error message: One or more of the specified arguments are not valid.

If I then edit properties of the task, then choose 'change user or group', then type 'x570' into the object name, then OK, it gets accepted. If after typing x570 into the object name field, then click 'check names', I get the same error message when trying to save the task. If I add another user to the PC, and type in that username instead, it works fine whether I check 'check names' or not.
A bug within task scheduler I think, or maybe windows doesn't like usernames beginning with x? who knows!

Update and now after adding another user called x470, I've disproved the x theory! And also found x570 works now whether I check names or not! I'm going to bed! :D

I'm in the same boat as the OP:

C:\WINDOWS\system32>powershell -ExecutionPolicy Bypass -File "H:\Utilities\PersistentWindows\auto_start_pw_aux.ps1"
Remove existing task.
TaskPath TaskName State


\ StartPersistentWindowsMe Ready
Set-ScheduledTask : The parameter is incorrect.
(10,56):UserId:Mandatory Label\Medium Mandatory Level
At H:\Utilities\PersistentWindows\auto_start_pw_aux.ps1:27 char:1

  • Set-ScheduledTask -TaskName $taskName -Settings $taskSettings
  •   + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Set-ScheduledTask
     ], CimException
      + FullyQualifiedErrorId : HRESULT 0x80070057,Set-ScheduledTask
    
    

Set-ScheduledTask : The parameter is incorrect.
(10,56):UserId:Mandatory Label\Medium Mandatory Level
At H:\Utilities\PersistentWindows\auto_start_pw_aux.ps1:30 char:1

  • Set-ScheduledTask -TaskName $taskName -TaskPath $task.TaskPath -Actio ...
  •   + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Set-ScheduledTask
     ], CimException
      + FullyQualifiedErrorId : HRESULT 0x80070057,Set-ScheduledTask
    
    

Set-ScheduledTask : The parameter is incorrect.
(10,56):UserId:Mandatory Label\Medium Mandatory Level
At H:\Utilities\PersistentWindows\auto_start_pw_aux.ps1:35 char:1

  • Set-ScheduledTask -TaskName $taskName -TaskPath $task.TaskPath -Princ ...
  •   + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Set-ScheduledTask
     ], CimException
      + FullyQualifiedErrorId : HRESULT 0x80070057,Set-ScheduledTask
    
    
    
    
    

C:\WINDOWS\system32>pause
Press any key to continue . . .

This issue is known to be caused by strict check of user name when executing PowerShell script to manage scheduled task by Windows OS

Some workaround:

  1. manually create a task directly in task scheduler, then re-execute auto_start_pw.bat again
  2. change user login name
  3. create PW shortcut entry in startup folder, at the cost of not being to run w/ admin privilege
    https://support.microsoft.com/en-us/windows/add-an-app-to-run-automatically-at-startup-in-windows-10-150da165-dcd9-7230-517b-cf3c295d89dd