i want an .exe file to be automatically executed if a folder having that particular file is opened,that's if you open the folder the file should get executed automatically.I want this to do in c++.can somebody help???

7 Years
Discussion Span
Last Post by ravenous



Well, that's the easy part. Now hook your program into the OS such that if a folder is access, the code is run. But first, consider why someone would want to do this. I can't think of a benign reason that wouldn't be better solved in another way.


Yeah, I don't know but I'd imagine that this would be a massive security hole if the operating system let do it! In any case, I don't think that there's anything that you could do in C++ that would give you this behaviour, since your C++ code doesn't come into effect until the program is executed. Choosing when to execute what is usually left up to the operating system. The system() call above will let you call one program from inside another, but definitely won't let you change the default behaviour of the operating system when a directory is clicked.

Why do you want to do this anyway? Perhaps there is a more standard way to solve the problem that you have. Unless you have something nefarious in mind, in which case, I'm not sure you'll get much help here!


I have done a program which gives a graphics text if its location matches the specificed location in the directory,that is the graphics text("welcome...") will be shown only if the file is kept in a foder say music.I have done it using getcwd().I want to that any facilities are there to execute it,if the folder is opened.


Okay, you've used more words to say "I want to run a program when the folder is accessed", but still haven't explained why that behavior is desired. When asking for something that smells malicious, you need to be very specific to convince us that you're not writing a some kind of trojan.

Edited by Narue: n/a


The only way to generate this behaviour should be to modify the code of the file manager that you're using, since that's what's making the decisions about what programs are executed when you click on things. I don't know if you can do this at all in Windows, but you could do it in one of the open source ones, such as Nautilus for Gnome, or Konqueror/Dolphin for KDE. I think that this would be a VERY time-consuming thing to do though (if you're not already familiar with the inner-workings of the code for your file manager, which I'm guessing you're not), and probably much harder than you're imagining it will be.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.