954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# code to deny access to local hard disk drives

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.......

getkiran1
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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.

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

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.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Good morning danny

You're working on the weekends too I see :P

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

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

getkiran1
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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.....

getkiran1
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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?

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

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.

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You