Showing posts with label access. Show all posts
Showing posts with label access. Show all posts

Monday, July 23, 2012

C# - Set Folder Permission


1 ) Set Access Control
DirectoryInfo dInfo = new DirectoryInfo(fileName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule("everyone",FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,PropagationFlags.InheritOnly,AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);


2) Sharing foldel
ManagementClass mc = new ManagementClass("win32_share");
ManagementBaseObject inParams = mc.GetMethodParameters("Create");
inParams("Description") = "My Shared Folder";
inParams("Name") = "Shared Folder Name";
inParams("Path") = "C:\\Folder1";
inParams("Type") = ShareResourceType.DiskDrive;
inParams("MaximumAllowed") = null;
inParams("Password") = null;
inParams("Access") = null; // Make Everyone has full control access.
ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null);


3) Only in Windows 7 and Vista, upgrade "Everyone" sharing right
//user selection
NTAccount ntAccount = new NTAccount("Everyone");

//SID
SecurityIdentifier userSID = (SecurityIdentifier)ntAccount.Translate(typeof(SecurityIdentifier));
byte[] utenteSIDArray = new byte[userSID.BinaryLength];
userSID.GetBinaryForm(utenteSIDArray, 0);

//Trustee
ManagementObject userTrustee = new ManagementClass(new ManagementPath("Win32_Trustee"), null);
userTrustee["Name"] = "Everyone";
userTrustee["SID"] = utenteSIDArray;

//ACE
ManagementObject userACE = new ManagementClass(new ManagementPath("Win32_Ace"), null);
userACE["AccessMask"] = 2032127;                                 //Full access
userACE["AceFlags"] = AceFlags.ObjectInherit | AceFlags.ContainerInherit;
userACE["AceType"] = AceType.AccessAllowed;
userACE["Trustee"] = userTrustee;

ManagementObject userSecurityDescriptor = new ManagementClass(new ManagementPath("Win32_SecurityDescriptor"), null);
userSecurityDescriptor["ControlFlags"] = 4; //SE_DACL_PRESENT 
userSecurityDescriptor["DACL"] = new object[] { userACE };

//UPGRADE SECURITY PERMISSION
ManagementClass mc = new ManagementClass("Win32_Share");
ManagementObject share = new ManagementObject(mc.Path + ".Name='" + CondivisionName + "'");
share.InvokeMethod("SetShareInfo", new object[] { Int32.MaxValue, description, userSecurityDescriptor });

Saturday, April 21, 2012

Android - Access SQLite Database File in Emulator


You have to be on the DDMS perspective on your Eclipse IDE
(Window > Open Perspective > Other > DDMS)
and the most important:
YOUR APPLICATION MUST BE RUNNING SO YOU CAN SEE THE HIERARCHY OF FOLDERS AND FILES.
Then in the File Explorer Tab you will follow the path :
data > data > your-package-name > databases > your-database-file.
Then select the file, click on the disket icon in the right corner of the screen to download the .db file. If you want to upload a database file to the emulator you can click on the phone icon(beside disket icon) and choose the file to upload.
If you want to see the content of the .db file, I advise you to use SQLite Database Browser, which you can download here.
PS: If you want to see the database from your real device, you must root your phone.