computer-use-ootb-internal 0.0.129__py3-none-any.whl → 0.0.131__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.
@@ -616,27 +616,39 @@ class GuardService(win32serviceutil.ServiceFramework):
616
616
  token = win32ts.WTSQueryUserToken(session_id)
617
617
  env = win32profile.CreateEnvironmentBlock(token, False)
618
618
  startup = win32process.STARTUPINFO()
619
- startup.dwFlags = win32process.STARTF_USESHOWWINDOW
620
- startup.wShowWindow = win32con.SW_HIDE
619
+ # No need to hide the window now, cmd /K will keep it open.
620
+ # startup.dwFlags = win32process.STARTF_USESHOWWINDOW
621
+ # startup.wShowWindow = win32con.SW_HIDE
621
622
  creation_flags = 0x00000010 # CREATE_NEW_CONSOLE
622
623
 
623
- self.log_info(f"Calling CreateProcessAsUser:")
624
- self.log_info(f" lpApplicationName: {self.target_executable_path}")
625
- self.log_info(f" lpCommandLine: {None}")
626
- self.log_info(f" lpCurrentDirectory: {os.path.dirname(self.target_executable_path) if os.path.dirname(self.target_executable_path) != '' else 'Default'}")
624
+ # --- Launch via cmd /K ---
625
+ # Use cmd.exe to launch the target, keeping the window open
626
+ lpApplicationName = None # We specify cmd.exe in the command line
627
+ # Ensure target path is quoted correctly within the command string
628
+ # self.target_executable_path should already be quoted if needed
629
+ lpCommandLine = f'cmd.exe /K "{self.target_executable_path}"'
630
+
631
+ # Determine CWD for the cmd process (can be None to use default)
632
+ cwd = os.path.dirname(self.target_executable_path.strip('"')) if os.path.dirname(self.target_executable_path.strip('"')) != '' else None
633
+ # --- End Launch via cmd /K ---
634
+
635
+ self.log_info(f"Calling CreateProcessAsUser to launch via cmd /K:")
636
+ self.log_info(f" lpApplicationName: {lpApplicationName}")
637
+ self.log_info(f" lpCommandLine: {lpCommandLine}")
638
+ self.log_info(f" lpCurrentDirectory: {cwd if cwd else 'Default'}")
627
639
  self.log_info(f" dwCreationFlags: {creation_flags} (CREATE_NEW_CONSOLE)")
628
640
 
629
641
  # CreateProcessAsUser call
630
642
  hProcess, hThread, dwPid, dwTid = win32process.CreateProcessAsUser(
631
643
  token, # User token
632
- self.target_executable_path, # Application name (the executable path)
633
- None, # Command line (None since it's in app name)
644
+ lpApplicationName, # Application name (None)
645
+ lpCommandLine, # Command line (cmd.exe /K "...")
634
646
  None, # Process attributes
635
647
  None, # Thread attributes
636
648
  False, # Inherit handles
637
649
  creation_flags, # Creation flags (CREATE_NEW_CONSOLE)
638
650
  env, # Environment block
639
- os.path.dirname(self.target_executable_path) if os.path.dirname(self.target_executable_path) != '' else None, # Current directory
651
+ cwd, # Current directory for cmd.exe
640
652
  startup # Startup info
641
653
  )
642
654
 
@@ -699,31 +711,33 @@ class GuardService(win32serviceutil.ServiceFramework):
699
711
  return "failed_exception"
700
712
 
701
713
  def create_or_update_logon_task(self, username):
702
- """Creates or updates a scheduled task to run the OOTB app on user logon."""
714
+ """Creates or updates a scheduled task to run the OOTB app via cmd /K on user logon."""
703
715
  if not self.target_executable_path:
704
716
  self.log_error(f"Cannot create task for {username}: Target executable path is not set.")
705
717
  return False
706
718
 
707
719
  task_name = f"OOTB_UserLogon_{username}"
708
- # Use the found target executable path directly
709
- # No arguments needed if the executable handles everything
710
- command_to_run = self.target_executable_path
711
- # Arguments are now empty as the exe is called directly
712
- arguments = ""
713
-
714
- # Ensure command_to_run is properly quoted if it contains spaces
715
- # The _find_target_executable should already handle quoting
716
- # Example PowerShell command construction (adjust as needed)
720
+ # Action: Execute cmd.exe
721
+ action_executable = "cmd.exe"
722
+ # Arguments for cmd.exe: /K "path\to\your\exe"
723
+ # self.target_executable_path should already be quoted if needed
724
+ action_arguments = f'/K "{self.target_executable_path}"'
725
+ # Escape single quotes for PowerShell command string if the path itself contains them (unlikely but possible)
726
+ safe_action_executable = action_executable.replace("'", "''")
727
+ safe_action_arguments = action_arguments.replace("'", "''")
728
+
729
+ # PowerShell command construction
717
730
  ps_command = f"""
718
731
  $taskName = "{task_name}"
719
732
  $principal = New-ScheduledTaskPrincipal -UserId "{username}" -LogonType Interactive
720
- # Action: Run the target executable directly
721
- $action = New-ScheduledTaskAction -Execute '{command_to_run}'
722
- # Optional: Set working directory if needed, otherwise it might default to System32 or user profile
723
- # $action.WorkingDirectory = "C:\path\to\working\dir"
733
+ # Action: Run cmd.exe with /K to launch the target executable and keep window open
734
+ $action = New-ScheduledTaskAction -Execute '{safe_action_executable}' -Argument '{safe_action_arguments}'
735
+ # Optional: Set working directory for cmd.exe if needed.
736
+ # Defaults often work, but could set explicitly to executable's dir:
737
+ # $action.WorkingDirectory = '{os.path.dirname(self.target_executable_path.strip('"')).replace("'", "''")}'
724
738
  $trigger = New-ScheduledTaskTrigger -AtLogOn -User "{username}"
725
739
  $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit (New-TimeSpan -Days 9999) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
726
- $description = "Runs OOTB Application for user {username} upon logon."
740
+ $description = "Runs OOTB Application (via cmd) for user {username} upon logon."
727
741
 
728
742
  # Unregister existing task first (force)
729
743
  Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
@@ -731,13 +745,46 @@ class GuardService(win32serviceutil.ServiceFramework):
731
745
  # Register the new task
732
746
  Register-ScheduledTask -TaskName $taskName -Principal $principal -Action $action -Trigger $trigger -Settings $settings -Description $description -Force
733
747
  """
734
- self.log_info(f"Attempting to create/update task '{task_name}' for user '{username}' to run '{command_to_run}'")
748
+ self.log_info(f"Attempting to create/update task '{task_name}' for user '{username}' to run '{action_executable} {action_arguments}'")
735
749
  try:
736
- # ... (run PowerShell command) ...
737
- self.log_info(f"Successfully ran PowerShell command to create/update task '{task_name}'.")
750
+ # Need to actually run the powershell command here!
751
+ success = self.run_powershell_command(ps_command)
752
+ if success:
753
+ self.log_info(f"Successfully ran PowerShell command to create/update task '{task_name}'.")
754
+ return True
755
+ else:
756
+ self.log_error(f"PowerShell command failed to create/update task '{task_name}'. See previous logs.")
757
+ return False
758
+ except Exception as e:
759
+ self.log_error(f"Failed to create/update scheduled task '{task_name}' for user '{username}': {e}", exc_info=True)
760
+ return False
761
+
762
+ def run_powershell_command(self, command, log_output=True):
763
+ """Executes a PowerShell command and handles output/errors. Returns True on success."""
764
+ self.log_info(f"Executing PowerShell: {command}")
765
+ try:
766
+ result = subprocess.run(
767
+ ["powershell.exe", "-NoProfile", "-NonInteractive", "-Command", command],
768
+ capture_output=True, text=True, check=True, encoding='utf-8', errors='ignore'
769
+ )
770
+ if log_output and result.stdout:
771
+ self.log_info(f"PowerShell STDOUT:\n{result.stdout.strip()}")
772
+ if log_output and result.stderr:
773
+ # Log stderr as info, as some commands write status here (like unregister task not found)
774
+ self.log_info(f"PowerShell STDERR:\n{result.stderr.strip()}")
738
775
  return True
776
+ except FileNotFoundError:
777
+ self.log_error("'powershell.exe' not found. Cannot manage scheduled tasks.")
778
+ return False
779
+ except subprocess.CalledProcessError as e:
780
+ # Log error but still return False, handled by caller
781
+ self.log_error(f"PowerShell command failed (Exit Code {e.returncode}):")
782
+ self.log_error(f" Command: {e.cmd}")
783
+ if e.stdout: self.log_error(f" STDOUT: {e.stdout.strip()}")
784
+ if e.stderr: self.log_error(f" STDERR: {e.stderr.strip()}")
785
+ return False
739
786
  except Exception as e:
740
- self.log_error(f"Failed to create/update scheduled task '{task_name}' for user '{username}': {e}")
787
+ self.log_error(f"Unexpected error running PowerShell: {e}", exc_info=True)
741
788
  return False
742
789
 
743
790
  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.129
3
+ Version: 0.0.131
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=ioavcDM3X3lyOY8nJe73isgQwo4FxQbXkZpWc_8RMas,41482
5
+ computer_use_ootb_internal/guard_service.py,sha256=IrYIlGc9E566-6fp1UHUjswR1ox02G5BuXzxmsaQxXA,44413
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.129.dist-info/METADATA,sha256=GkyTYGPcqy0XyaKiHsOGPHRVY8RZorcqLtqR8dUGhe0,1048
37
- computer_use_ootb_internal-0.0.129.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
- computer_use_ootb_internal-0.0.129.dist-info/entry_points.txt,sha256=bXfyAU_qq-G1EiEgAQEioXvgEdRCFxaTooqdDD9Y4OA,258
39
- computer_use_ootb_internal-0.0.129.dist-info/RECORD,,
36
+ computer_use_ootb_internal-0.0.131.dist-info/METADATA,sha256=G74lBKml5gQWvA51NllSzlvNxkdiSVeXW7jtpJLi1RQ,1048
37
+ computer_use_ootb_internal-0.0.131.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
38
+ computer_use_ootb_internal-0.0.131.dist-info/entry_points.txt,sha256=bXfyAU_qq-G1EiEgAQEioXvgEdRCFxaTooqdDD9Y4OA,258
39
+ computer_use_ootb_internal-0.0.131.dist-info/RECORD,,