Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

.net - How could I prevent a folder from being created using a windows service?

I have users and processes on a web server. I'm looking to write a windows service that is capable of intercepting calls to create folders within a specific sub-directory. I've found several sources out there for reactively catching that a folder was created, but I want to create a windows service that will proactively intercept and pre-empt any unacceptable calls to create the folder.

Let me pre-empty the "why"-ers. Don't bother asking why. Suffice it to say I've been asked to do this, and I'm trying to find the simplest method of accomplishing the task in an automated way. I've already determined how to accomplish it if I let the folder get created then just follow along with my windows service and delete it (and its contents) after the fact. I really would like an event I could have the service listen to and pre-empt.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unfortunately I don't know anywhere near enough about the how to help you, but I'm fairly sure that you'll need to either write or obtain a File System Filter Driver that can communicate with your windows service to tell it that someone has attempted to create a directory/file so that your service can make a decision for it. This way when someone/something attempts to create a file or folder that's not allowed they could be returned "Access Denied" or another Win32 error of your choice.

If you did go down the route of using a driver, I'd guess it'd still be best to do the heavy lifting of deciding if the creation/modification in the service, i.e. outside of Kernel mode.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...