Python Forum
Python win32com.client: What are the syntax to open exe file & activate its window?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python win32com.client: What are the syntax to open exe file & activate its window?
#1
I am completely lost in using "win32com.client" to open an exe program and run it. I used the code appended at the end, but I get the following error:
 
File "C:\Program Files\Anaconda3\lib\site-packages\win32com\client_init_.py", line 113, in DispatchEx dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx, serverInfo, (pythoncom.IID_IDispatch,))[0]
com_error: (-2147221005, 'Invalid class string', None, None)
 
I am quite lost, and hope someone could assist. Thank you!
 
1st: do I state the exe prog complete file path here?
shell = w3c.DispatchEx('C:/Program Files/FAME.exe')
2nd: is it correct to use FAME to refer to the application here?
shell.Run('FAME')
3rd: For AppActivate, is the argument the title bar of my application?
shell.AppActivate('FAME')
 




Complete Code
import win32com.client as w3c 
shell = w3c.DispatchEx('C:/Program Files/FAME.exe')
shell.Run('FAME') 
time.sleep(5) 
shell.AppActivate('FAME') 
shell.SendKeys("input +""C:\programs\FAMESCRIPT.txt""+{ENTER}", 1)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  open a text file using list() Pedroski55 2 115 Feb-25-2026, 06:57 PM
Last Post: noisefloor
  If I open a file write or append, is the file loaded into RAM? Pedroski55 11 1,118 Jan-14-2026, 07:49 AM
Last Post: Pedroski55
Question [SOLVED] Open file, and insert space in string? Winfried 7 2,524 May-28-2025, 07:56 AM
Last Post: Winfried
  Trying to open depracated joblib file mckennamason 0 2,156 Sep-19-2024, 03:30 PM
Last Post: mckennamason
  client A to server B connects but client B to server A doesnt connect gerald 1 1,518 Aug-17-2024, 07:33 AM
Last Post: Gribouillis
  How can I upload a .gz file to the Swift Object Storage using Python swift client? Hanginium65 0 1,223 Jul-24-2024, 03:24 PM
Last Post: Hanginium65
  Open files in an existing window instead of new Kostov 2 2,117 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Open/save file on Android frohr 0 2,187 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 17,397 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 7,905 Oct-02-2023, 04:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020