1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Rep Power

    Running a python script by opening a .exe

    Is it possible to write a python script that will execute anytime someones opens a certain .exe file? Basically I have written a script that opens a text file containing warning and disclaimer information, and I need it to open on the users screen anytime he/she opens this particular program. Any help in the write direction would be appreciated.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    What do you mean?

    Do you want a notice to appear if this code executes?
    For this to work you'd need serious file system support---the file system would need the ability to call back your code when it opens files.

    Do you need the notice to appear if someone runs it?
    shellPrompt$ certain.exe
    If you wrote the certain program you could modify it to display your notice. If you don't have the certain source then instead you could include certain.exe as data in your own program, which would then display the notice, write the program as a temporary file, and then fork to it.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Rep Power
    I'll assume the obvious answer of change the shortcut to a batch file that displays the warning message before running the exe is not possible.

    You can find out a list of running processes using a WMI query. For example if the WQL SELECT * FROM Win32_Process WHERE Description = 'notepad.exe' this will return all the occurrances of notepad or nothing if notepad is not running.

    I put a some information on using WMI with Python on my blog(quackajack.wordpress.com) if that helps.

    If you want to get information on processes being started, I'm not sure that is going to be possible without elevating permissions. I saw an article on hooking into the API for process creation on The Code Project but it is not going to be easy to replicate in Python.

IMN logo majestic logo threadwatch logo seochat tools logo