2010-03-01 4 views
0

Je souhaite refuser/lire l'accès aux lecteurs amovibles à l'aide de ACL. J'ai cherché et trouvé que je peux être fait en utilisant setsecurityinfo.Refus/Accès en lecture seule aux lecteurs amovibles

je faisais référence et Msdn pinvoke.net mais pas en mesure de mettre avec succès

Aide en C# ou Vb.net nécessaire

Répondre

0

MSDN a l'exemple suivant pour la classe FileSystemAccessRule:

// Removes an ACL entry on the specified file for the specified account. 
    public static void RemoveFileSecurity(string fileName, string account, 
     FileSystemRights rights, AccessControlType controlType) 
    { 

     // Get a FileSecurity object that represents the 
     // current security settings. 
     FileSecurity fSecurity = File.GetAccessControl(fileName); 

     // Remove the FileSystemAccessRule from the security settings. 
     fSecurity.RemoveAccessRule(new FileSystemAccessRule(account, 
      rights, controlType)); 

     // Set the new access settings. 
     File.SetAccessControl(fileName, fSecurity); 

    } 

Vous devriez construire votre solution spécifique basée sur ceci. N'oubliez pas que vous devez être le propriétaire ou avoir le droit de «modifier les droits» pour effectuer ces modifications.

+0

merci mais l'exemple ci-dessus est uniquement pour les fichiers et non pour les volumes – bts

0
[DllImport("advapi32.dll", CharSet = CharSet.Unicode)] 

extern statique privé uint SetNamedSecurityInfoW (String pObjectName, SE_OBJECT_TYPE TypeObjet, SECURITY_INFORMATION SecurityInfo, IntPtr psidOwner, IntPtr psidGroup, IntPtr pDacl, IntPtr pSacl);

private void Form1_Load(object sender, EventArgs e) 
    { 
    SetNamedSecurityInfo ("\\\\.\\K:",SE_OBJECT_TYPE.SE_FILE_OBJECT,SECURITY_INFORMATION.ProtectedDacl, null, null, null, null); 

    } 

    private void SetNamedSecurityInfo(string p, object SE_FILE_OBJECT, object DACL_SECURITY_INFORMATION, object NULL, object NULL_5, object paclNew, object NULL_7) 
    { 
     throw new Exception("The method or operation is not implemented."); 
    } 

[DllImport ("Advapi32.dll", SetLastError = true)] extern private static bool ConvertStringSidToSid (String StringSid, ref IntPtr Sid);

ENUM privé SE_OBJECT_TYPE { SE_UNKNOWN_OBJECT_TYPE = 0,
SE_FILE_OBJECT, SE_SERVICE, SE_PRINTER, SE_REGISTRY_KEY, SE_LMSHARE, SE_KERNEL_OBJECT, SE_WINDOW_OBJECT, SE_DS_OBJECT, SE_DS_OBJECT_ALL, SE_PROVIDER_DEFINED_OBJECT, SE_WMIGUID_OBJECT, SE_REGISTRY_WOW64_32KEY }

[F retards] ENUM privé SECURITY_INFORMATION: uint { Propriétaire = 0x00000001, groupe = 0x00000002, DACL = 0x00000004, Sacl = 0x00000008, ProtectedDacl = 0x80000000, ProtectedSacl = 0x40000000, UnprotectedDacl = 0x20000000, UnprotectedSacl = 0x10000000 }

où k: est le lecteur amovible