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 files in an existing window instead of new Kostov 2 302 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Open/save file on Android frohr 0 333 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,132 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 1,777 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 887 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  How can i combine these two functions so i only open the file once? cubangt 4 867 Aug-14-2023, 05:04 PM
Last Post: snippsat
  Open a new window does not work Nietzsche 4 1,089 Jun-14-2023, 08:52 AM
Last Post: Nietzsche
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 734 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Getting "SSL client not supported by this Python installation" error prabirsarkar 0 963 Mar-13-2023, 05:01 PM
Last Post: prabirsarkar
  I cannot able open a file in python ? ted 5 3,358 Feb-11-2023, 02:38 AM
Last Post: ted

Forum Jump:

User Panel Messages

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