Skip to content

[Windows] Automated Login via Scheduled Task with Network-Aware Execution #60

Description

@KJH-x

Problems:
A feature request comes from a member of the 网协电脑诊所线上咨询 group.

Challenges:

  1. The login attempt may occur before the internet connection is established, leading to potential failures.
  2. The script requires PowerShell to run as an administrator, which triggers User Account Control (UAC) prompts.

Requirements:
To implement the auto logon process successfully, the following parameters must be known and correctly set:

  1. $executable_path – The full path of the executable that initiates the login process.
  2. $your_executable_parameters – The command-line parameters required for login, for example:
    login --username yourUserName --password yourPassword
    This ensures the login command runs with the appropriate credentials.

PowerShell Script

$executable_path="path/to/bitsrun"
$your_executable_parameters="login --username yourUserName --password yourPassword"

Register-ScheduledTask -Action (New-ScheduledTaskAction -Execute $executable_path -Argument "your_executable_parameters") -Trigger (New-ScheduledTaskTrigger -AtLogon) -Settings (New-ScheduledTaskSettingsSet -NetworkId "BIT-web" -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -DontStopOnIdleEnd -ExecutionTimeLimit 0) -Principal (New-ScheduledTaskPrincipal -UserId $Env:UserName -LogonType Interactive) -TaskName "Bitsrun" -Description "Bitsrun Login At User Logon"

Key Parameters and Their Functions

  • NetworkId "BIT-web": Ensures the task runs only when connected to the specified network, preventing execution when offline.
  • AllowStartIfOnBatteries: Enables the task to run even if the device is on battery power, ensuring uninterrupted login.
  • DontStopIfGoingOnBatteries: Prevents the task from stopping if the power source switches to battery mode.
  • StartWhenAvailable: If the task fails to execute at the scheduled time (e.g., due to the device being off), it will start as soon as possible when conditions allow.
  • MultipleInstances IgnoreNew: If the task is already running, additional instances will be ignored to avoid conflicts.
  • DontStopOnIdleEnd: Ensures that the task continues running even when the system transitions to an idle state.
  • ExecutionTimeLimit 0: Removes any time limit for the task execution, allowing it to run indefinitely until manually stopped.

This configuration ensures reliable auto logon while minimizing potential interruptions due to system conditions such as power state or network availability.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions