Hi,

Im Kiran. Can any one help me with the C# code for denying access to the local drives?? when anyone try to access a drive ( thru cmd or double clicking the drive directly) it shud nt b allowed.. for that..
So hw can we do that programattically..???

Plz help me.......

You can't. Whatever you are trying to do you are going about it the wrong way. This is more to do with security policies than programming.

I think the closest you can get to the thing you want is to use a FileSystemWatcher class. But that will only work when your program is active of course.

hi sknake....
dnt knw y u said a big NO.... sorry, we can do with the System.Management namespace... i did dat bt still some prblm is der.. i mean i can deny access to read,write,delete etc but i cannot change it back to the allowed state... Classes are there like
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.FullControl, AccessControlType.Allow)); but it is nt wrkng unfortunately.. dats y....

Its possible with System.Management namespace ... ok???

Thankzzzzzzz

hi ddanbe..
First of all thanx 4 ur reply...
Well i had done dat partilly with System.Management namespace... bt still som prblms... dats y...
ok i will check d FiuleSystemWatcher and wll let u knw..
Thanku sir.....

sknake is right... This isn't a programming problem. This is more something that should be resolved by local security policies on a client machine. Are these machines part of a domain?

file systems manage drives access, not programs or operating systems. you can modify the filing system's access rights to users by using applications to modify the security permissions in the filing system, but It wasn't designed to be modified frequently like that. you could end up with a completely inaccessible drive.

There are much better ways to go about it. I agree with Scott and Dan. not only can you not. If you do find a way, you most certainly shouldn't.

This article has been dead for over six months. Start a new discussion instead.