Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to make a usb drive to write only drive mean read protected drive using this method but its not working. Can anyone help me to sort this out? why it's not working.
C#
public void writeOnlyDirectory(string storageLocation)
{
    string User = System.Environment.UserName.ToString();
    string drive = storageLocation.Substring(0, 3);        

    DirectoryInfo myDirectoryInfo = new DirectoryInfo(drive);
    DirectorySecurity sec = Directory.GetAccessControl(myDirectoryInfo.ToString());
    SecurityIdentifier Everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

    sec.RemoveAccessRuleAll(new FileSystemAccessRule(Everyone, FileSystemRights.FullControl, AccessControlType.Allow));
            
//Give current user full rights
    sec.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.FullControl | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
            
    sec.AddAccessRule(new FileSystemAccessRule(Everyone, FileSystemRights.Write | FileSystemRights.ListDirectory, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
            
    try
      {
          Directory.SetAccessControl(myDirectoryInfo.ToString(), sec);
          MessageBox.Show("Permissions Altered Successfully");
      }
    catch (PrivilegeNotHeldException ex)
      {
          MessageBox.Show(ex.Message);
      }
}
Posted
Updated 10-Oct-15 4:30am
v2
Comments
Philippe Mori 10-Oct-15 12:12pm    
It does not make much sense... What is the purpose of writing data if it cannot be read back?
Shahzad Mirza 10-Oct-15 12:17pm    
I am just trying to make a USB drive that can pass onto everyone to collect data but no one can change data and can only be readable by administrator account who make that usb write only.
BillWoodruff 10-Oct-15 12:49pm    
Start here:

http://www.codeproject.com/Articles/36976/Developing-a-USB-Storage-Device-Protection-Tool-wi
Shahzad Mirza 10-Oct-15 12:55pm    
Thanks but i already tried it and it only work on PC. But i am trying to change permissions of usb using NTFS File Systems security. The code i have posted that is dealing with my question but the problem is this code do not change permissions to write only.

1 solution

Quote:
I am trying to make a usb drive to write only drive mean read protected drive using this method but its not working.

This is pointless because you just have to plug the usb drive to a Linux system and you have access to the data, no matter what windows says.
Another problem, it is common for OS to reread data to check that writing is OK.

To Do what you want, you need to make a program to read/write in a single encrypted file.
You stored the data in a big encrypted file. The downside of this is that you have to create you own file system.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900