computer-use-ootb-internal 0.0.130__py3-none-any.whl → 0.0.132__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -711,45 +711,107 @@ class GuardService(win32serviceutil.ServiceFramework):
711
711
  return "failed_exception"
712
712
 
713
713
  def create_or_update_logon_task(self, username):
714
- """Creates or updates a scheduled task to run the OOTB app on user logon."""
714
+ """Creates/updates task to run OOTB app via cmd /K on session connect (RDP/Console)."""
715
715
  if not self.target_executable_path:
716
716
  self.log_error(f"Cannot create task for {username}: Target executable path is not set.")
717
717
  return False
718
718
 
719
- task_name = f"OOTB_UserLogon_{username}"
720
- # Use the found target executable path directly
721
- # No arguments needed if the executable handles everything
722
- command_to_run = self.target_executable_path
723
- # Arguments are now empty as the exe is called directly
724
- arguments = ""
719
+ task_name = f"OOTB_UserConnect_{username}" # Renamed task slightly
720
+ action_executable = "cmd.exe"
721
+ action_arguments = f'/K "{self.target_executable_path}"'
722
+ safe_action_executable = action_executable.replace("'", "''")
723
+ safe_action_arguments = action_arguments.replace("'", "''")
724
+
725
+ # Explicitly set the working directory to the executable's location
726
+ try:
727
+ executable_dir = os.path.dirname(self.target_executable_path.strip('"'))
728
+ if not executable_dir: # Handle case where path might be just the exe name
729
+ executable_dir = "." # Use current directory as fallback?
730
+ self.log_warning(f"Could not determine directory for {self.target_executable_path}, task WorkingDirectory might be incorrect.")
731
+ safe_working_directory = executable_dir.replace("'", "''")
732
+ working_directory_setting = f"$action.WorkingDirectory = '{safe_working_directory}'"
733
+ except Exception as e:
734
+ self.log_error(f"Error determining working directory for task: {e}. WorkingDirectory will not be set.")
735
+ working_directory_setting = "# Could not set WorkingDirectory" # Comment out in PS script
725
736
 
726
- # Ensure command_to_run is properly quoted if it contains spaces
727
- # The _find_target_executable should already handle quoting
728
- # Example PowerShell command construction (adjust as needed)
737
+ # PowerShell command construction
729
738
  ps_command = f"""
730
739
  $taskName = "{task_name}"
731
740
  $principal = New-ScheduledTaskPrincipal -UserId "{username}" -LogonType Interactive
732
- # Action: Run the target executable directly
733
- $action = New-ScheduledTaskAction -Execute '{command_to_run}'
734
- # Optional: Set working directory if needed, otherwise it might default to System32 or user profile
735
- # $action.WorkingDirectory = "C:\path\to\working\dir"
736
- $trigger = New-ScheduledTaskTrigger -AtLogOn -User "{username}"
741
+
742
+ # Action: Run cmd.exe with /K, setting the working directory
743
+ $action = New-ScheduledTaskAction -Execute '{safe_action_executable}' -Argument '{safe_action_arguments}'
744
+ {working_directory_setting}
745
+
746
+ # Trigger: On session connect/reconnect events for Terminal Services
747
+ $logName = 'Microsoft-Windows-TerminalServices-LocalSessionManager/Operational'
748
+ $source = 'Microsoft-Windows-TerminalServices-LocalSessionManager'
749
+ $eventIDs = @(21, 25) # 21=SessionLogon, 25=SessionReconnect
750
+ # The Principal -UserId should ensure this only runs for the target user when they connect
751
+ $trigger = New-ScheduledTaskTrigger -AtLogOn # Keep AtLogOn as a fallback?
752
+ # --- Let's stick to ONE trigger type first. Replacing AtLogOn with Event ---
753
+ # $trigger = New-ScheduledTaskTrigger -AtLogOn -User "{username}"
754
+ $trigger = New-ScheduledTaskTrigger -Event -LogName $logName -Source $source -EventId $eventIDs[0] # Primary trigger
755
+ # Register additional triggers if needed, or handle logic differently.
756
+ # For simplicity, let's try one event trigger first (ID 21). If reconnect (25) is needed, we can add it.
757
+ # Consider adding delay: -Delay 'PT15S' # Delay 15 seconds after event?
758
+
737
759
  $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit (New-TimeSpan -Days 9999) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
738
- $description = "Runs OOTB Application for user {username} upon logon."
760
+ $description = "Runs OOTB Application (via cmd) for user {username} upon session connect (Event Trigger)." # Updated description
739
761
 
740
- # Unregister existing task first (force)
762
+ # Unregister existing task first (force) - Use the NEW task name
741
763
  Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
742
764
 
743
765
  # Register the new task
744
766
  Register-ScheduledTask -TaskName $taskName -Principal $principal -Action $action -Trigger $trigger -Settings $settings -Description $description -Force
767
+
768
+ # Optional: Add second trigger for event ID 25 (Reconnect)
769
+ # Requires creating a separate trigger object and adding it.
770
+ # $trigger2 = New-ScheduledTaskTrigger -Event -LogName $logName -Source $source -EventId $eventIDs[1]
771
+ # Set-ScheduledTask -TaskName $taskName -Trigger $trigger, $trigger2 # This replaces existing triggers
772
+ # Append trigger is more complex via PowerShell cmdlets, often easier via XML or COM
773
+
745
774
  """
746
- self.log_info(f"Attempting to create/update task '{task_name}' for user '{username}' to run '{command_to_run}'")
775
+ self.log_info(f"Attempting to create/update task '{task_name}' for user '{username}' to run '{action_executable} {action_arguments}' on session connect.")
747
776
  try:
748
- # ... (run PowerShell command) ...
749
- self.log_info(f"Successfully ran PowerShell command to create/update task '{task_name}'.")
777
+ # Need to actually run the powershell command here!
778
+ success = self.run_powershell_command(ps_command)
779
+ if success:
780
+ self.log_info(f"Successfully ran PowerShell command to create/update task '{task_name}'.")
781
+ return True
782
+ else:
783
+ self.log_error(f"PowerShell command failed to create/update task '{task_name}'. See previous logs.")
784
+ return False
785
+ except Exception as e:
786
+ self.log_error(f"Failed to create/update scheduled task '{task_name}' for user '{username}': {e}", exc_info=True)
787
+ return False
788
+
789
+ def run_powershell_command(self, command, log_output=True):
790
+ """Executes a PowerShell command and handles output/errors. Returns True on success."""
791
+ self.log_info(f"Executing PowerShell: {command}")
792
+ try:
793
+ result = subprocess.run(
794
+ ["powershell.exe", "-NoProfile", "-NonInteractive", "-Command", command],
795
+ capture_output=True, text=True, check=True, encoding='utf-8', errors='ignore'
796
+ )
797
+ if log_output and result.stdout:
798
+ self.log_info(f"PowerShell STDOUT:\n{result.stdout.strip()}")
799
+ if log_output and result.stderr:
800
+ # Log stderr as info, as some commands write status here (like unregister task not found)
801
+ self.log_info(f"PowerShell STDERR:\n{result.stderr.strip()}")
750
802
  return True
803
+ except FileNotFoundError:
804
+ self.log_error("'powershell.exe' not found. Cannot manage scheduled tasks.")
805
+ return False
806
+ except subprocess.CalledProcessError as e:
807
+ # Log error but still return False, handled by caller
808
+ self.log_error(f"PowerShell command failed (Exit Code {e.returncode}):")
809
+ self.log_error(f" Command: {e.cmd}")
810
+ if e.stdout: self.log_error(f" STDOUT: {e.stdout.strip()}")
811
+ if e.stderr: self.log_error(f" STDERR: {e.stderr.strip()}")
812
+ return False
751
813
  except Exception as e:
752
- self.log_error(f"Failed to create/update scheduled task '{task_name}' for user '{username}': {e}")
814
+ self.log_error(f"Unexpected error running PowerShell: {e}", exc_info=True)
753
815
  return False
754
816
 
755
817
  def remove_logon_task(self, username):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: computer-use-ootb-internal
3
- Version: 0.0.130
3
+ Version: 0.0.132
4
4
  Summary: Computer Use OOTB
5
5
  Author-email: Siyuan Hu <siyuan.hu.sg@gmail.com>
6
6
  Requires-Python: >=3.11
@@ -2,7 +2,7 @@ computer_use_ootb_internal/README.md,sha256=FxpW95lyub2iX73ZDfK6ML7SdEKg060H5I6G
2
2
  computer_use_ootb_internal/__init__.py,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
3
3
  computer_use_ootb_internal/app_teachmode.py,sha256=ZZW98870QPNK76LN4f4k9RjBELYcF_3hl0w0fvxj3dY,22268
4
4
  computer_use_ootb_internal/dependency_check.py,sha256=y8RMEP6RXQzTgU1MS_1piBLtz4J-Hfn9RjUZg59dyvo,1333
5
- computer_use_ootb_internal/guard_service.py,sha256=llX4LwVHtkuEwDo22zSTcfTwbSUtV8LHqRJ1mQY60yM,42257
5
+ computer_use_ootb_internal/guard_service.py,sha256=4DHx37HV9wiTBo-8vYEMqnJf75zzc5Dv6GW0mSH_jhU,46372
6
6
  computer_use_ootb_internal/requirements-lite.txt,sha256=5DAHomz4A_P2BmTIXNkNqkHbnIF0AyZ4_1XAlb1LaYs,290
7
7
  computer_use_ootb_internal/run_teachmode_ootb_args.py,sha256=HB7L9vuIPUXVqeTicyNJKArzTNAfgdpsyO3JEzmByIo,7315
8
8
  computer_use_ootb_internal/service_manager.py,sha256=SD8jzfn0VVXBOr_nP6zmBWSC2TzrU_sp2e5JJkSlQFU,9734
@@ -33,7 +33,7 @@ computer_use_ootb_internal/computer_use_demo/tools/run.py,sha256=xhXdnBK1di9muaO
33
33
  computer_use_ootb_internal/computer_use_demo/tools/screen_capture.py,sha256=L8qfvtUkPPQGt92N-2Zfw5ZTDBzLsDps39uMnX3_uSA,6857
34
34
  computer_use_ootb_internal/preparation/__init__.py,sha256=AgtGHcBpiTkxJjF0xwcs3yyQ6SyUvhL3G0vD2XO-zJw,63
35
35
  computer_use_ootb_internal/preparation/star_rail_prepare.py,sha256=s1VWszcTnJAKxqCHFlaOEwPkqVSrkiFx_yKpWSnSbHs,2649
36
- computer_use_ootb_internal-0.0.130.dist-info/METADATA,sha256=aa0FwxmrC7SAWdR9sNz2yH5VXvRCw2dCBpKX-O5sMN4,1048
37
- computer_use_ootb_internal-0.0.130.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
- computer_use_ootb_internal-0.0.130.dist-info/entry_points.txt,sha256=bXfyAU_qq-G1EiEgAQEioXvgEdRCFxaTooqdDD9Y4OA,258
39
- computer_use_ootb_internal-0.0.130.dist-info/RECORD,,
36
+ computer_use_ootb_internal-0.0.132.dist-info/METADATA,sha256=Y60PbDx8fQwtijNHWj5-wm-6KPNyT8Ex8T-3JMdzvbc,1048
37
+ computer_use_ootb_internal-0.0.132.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
+ computer_use_ootb_internal-0.0.132.dist-info/entry_points.txt,sha256=bXfyAU_qq-G1EiEgAQEioXvgEdRCFxaTooqdDD9Y4OA,258
39
+ computer_use_ootb_internal-0.0.132.dist-info/RECORD,,