Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

run an exe or batch file when a folder is opend

Aug 25, 2011 6:52PM PDT

Hi everyone,
I want to run an exe or batch file at opening of a file.
It is similar to insert a game or software cd into cd drive and the exe will run automatically.
Can any one help me ?

thanks.

Discussion is locked

- Collapse -
Answer
Re: opening
Aug 25, 2011 6:58PM PDT

In your subject line you say you want to run an exe or batch file when a FOLDER is opened.
In your post you say you want to run an exe or batch file when a FILE is opened.

Can you tell WHAT you want, with an appropiate example?

Kees

- Collapse -
run an exe or batch file when a folder is opend
Aug 25, 2011 8:35PM PDT

sorry for mistake actually it folder.

Let one folder ABC is present inside e drive.Now i want to open it.When i will open it i want to run an exe which will show some message or write some message in a file.

- Collapse -
Not a feature of Windows.
Aug 25, 2011 9:13PM PDT

I even doubt if "opening a folder" is a well defined event.

Kees

- Collapse -
re
Aug 25, 2011 9:34PM PDT

When you are trying to open a folder something should happen in side os.So that if a virus is inside a folder and when you want to open the folder it automatically detected by anti-virus.

- Collapse -
I don't think so.
Aug 25, 2011 9:48PM PDT

Antivirus is triggered by opening a file, not a folder. Suppose you open c:\windows\system32. Contains a few hundred executables. It would be much too time consuming if your antivirus would check all just because you show all those files in the right pane in Windows Explorer.

Kees

- Collapse -
may be the soln.
Aug 25, 2011 10:23PM PDT

Ok thanks for reply.
Though opening a folder is not a well defined event we can not detect it.

Can you plz tell me one thing ?
when a folder is clicked for open, at that time what is happened inside os.

bibhu.

- Collapse -
Re: opening a folder
Aug 25, 2011 10:27PM PDT

I think the last access timestamp is being set and that's all.

Kees

- Collapse -
re
Aug 25, 2011 10:46PM PDT

can you plz explain a little more ?

- Collapse -
I don't think I can.
Aug 25, 2011 11:00PM PDT

Moreover, it wouldn't help you to reach your goal.

Kees

- Collapse -
Answer
I'll say no
Aug 25, 2011 11:11PM PDT

I'll say no, in that this isn't possible. Because while that isn't strictly true, this would be a VERY dangerous thing to do, and you would need to have some EXTREMELY well tested code before implementing it, because any bugs would affect EVERY folder you try and open, which would make fixing it a bit troublesome.

And AV programs already automatically scan files on access, the exception being ClamAV which has no resident scanner last I checked. All others have been doing this for probably the last 15 years give or take. So all you'd be doing with your little project is adding in pointless overhead to the system.

This is an idea best forgotten. The possibilities for unintended consequences are very very high, which is why Microsoft made it rather difficult to be able to trap this particular event with a program.

- Collapse -
Answer
As a programmer.
Aug 26, 2011 12:20AM PDT

You could have to dig in deep to make this happen. It's not built into the OS and it's not a feature of the app we call Windows Explorer.

For example when I run the command CMD and CD to a folder, that uses some code in the OS and when you use Explorer that triggers other code and when I use Gyula's Navigator, yet other code in the OS is used.

All this without any common event for your programmer to latch onto to make this happen.

-> Having shared this did you try putting an AUTORUN.INF and such in a folder?
Bob

- Collapse -
reply
Aug 26, 2011 2:57PM PDT

I tried that one before posting.
I put a autorun.inf file inside a folder and i tried to open the folder but it did not work.
My file contains [autorun] open=setup.exe
and setup.exe is present inside the folder.

bibhu.

- Collapse -
(NT) Doesn't surprise me it doesn't work.
Aug 27, 2011 12:14AM PDT
- Collapse -
Worth a shot.
Aug 27, 2011 2:30AM PDT

I did see it work when the folder was SUBST for a drive letter but given the AUTORUN exploits almost all versions of Windows are now disallowing autorun without a warning.

As the saying goes, "This is not the OS you are looking for."
Bob