July 12th, 2012, 11:10 AM
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.
July 12th, 2012, 06:02 PM
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?
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] are essential for python code and Makefiles!
July 13th, 2012, 10:46 AM
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.