private static NtDirectory OpenNamespace(string path) { using (BoundaryDescriptor boundary = BoundaryDescriptor.CreateFromString(path)) { return(NtDirectory.OpenPrivateNamespace(boundary)); } }
/// <summary> /// Overridden method to create a new drive. /// </summary> /// <param name="drive">The template drive info.</param> /// <returns>The new drive info.</returns> protected override PSDriveInfo NewDrive(PSDriveInfo drive) { if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException(nameof(drive)), "NullDrive", ErrorCategory.InvalidArgument, null)); return(null); } if (string.IsNullOrWhiteSpace(drive.Root) && (!drive.Root.StartsWith(GLOBAL_ROOT) || !drive.Root.StartsWith(NAMESPACE_ROOT))) { WriteError(new ErrorRecord( new ArgumentNullException("drive.Root"), "InvalidRoot", ErrorCategory.InvalidArgument, null)); return(null); } try { if (drive.Root.StartsWith(NAMESPACE_ROOT)) { using (var descriptor = BoundaryDescriptor.CreateFromString(drive.Root.Substring(NAMESPACE_ROOT.Length))) { using (NtDirectory dir = NtDirectory.OpenPrivateNamespace(descriptor)) { ObjectManagerPSDriveInfo objmgr_drive = new ObjectManagerPSDriveInfo(dir.Duplicate(), drive); return(objmgr_drive); } } } else { using (NtDirectory root = NtDirectory.Open(@"\")) { using (NtDirectory dir = NtDirectory.Open(drive.Root.Substring(GLOBAL_ROOT.Length), root, DirectoryAccessRights.MaximumAllowed)) { ObjectManagerPSDriveInfo objmgr_drive = new ObjectManagerPSDriveInfo(dir.Duplicate(), drive); return(objmgr_drive); } } } } catch (NtException ex) { WriteError(new ErrorRecord( ex, "NoRoot", ErrorCategory.PermissionDenied, drive)); return(null); } }
static NtDirectory OpenDirectory(string name) { if (name.StartsWith(@"\")) { return(NtDirectory.Open(name)); } else { return(NtDirectory.OpenPrivateNamespace(BoundaryDescriptor.CreateFromString(name))); } }
public NtDirectory OpenDirectory() { if (Name.StartsWith(@"\") || Directory != null) { return(NtDirectory.Open(Name, Directory, DirectoryAccessRights.MaximumAllowed)); } else { return(NtDirectory.OpenPrivateNamespace(BoundaryDescriptor.CreateFromString(Name))); } }
/// <summary> /// Method to create an object from a set of object attributes. /// </summary> /// <param name="obj_attributes">The object attributes to create/open from.</param> /// <returns>The newly created object.</returns> protected override object CreateObject(ObjectAttributes obj_attributes) { if (PrivateNamespaceDescriptor != null) { using (BoundaryDescriptor descriptor = BoundaryDescriptor.CreateFromString(PrivateNamespaceDescriptor)) { return(NtDirectory.OpenPrivateNamespace(obj_attributes, descriptor, Access)); } } else { return(NtDirectory.Open(obj_attributes, Access)); } }
private static NtDirectory OpenNamespace(string path) { try { using (BoundaryDescriptor boundary = BoundaryDescriptor.CreateFromString(path)) { return(NtDirectory.OpenPrivateNamespace(boundary)); } } catch (NtException ex) { throw ex.AsWin32Exception(); } }