private static void ShareFolder(ILogger logger, DirectoryPath directoryPath, ShareName shareName, string shareDescription) { logger.LogDebug(string.Format("Starts trying to share {0} as {1}", directoryPath, shareName)); WindowsShare.MethodStatus methodStatus = WindowsShare.Create(directoryPath.PathString, shareName.ToString(), WindowsShare.ShareType.DiskDrive, null, shareDescription, null); if (methodStatus != WindowsShare.MethodStatus.Success) { throw new ShareException(string.Format("Creating share failed for {0} at {1}. Error {2}.", shareName, directoryPath, methodStatus.ToString())); } logger.LogInfo(string.Format("Share {0} created for {1}.", shareName, directoryPath)); }
private static void SharePermissions(ILogger logger, ShareName shareName, string domain, string user, WindowsShare.AccessMaskTypes accessMask) { logger.LogDebug(string.Format("Trying to set permissions to share {0} for user {1}\\{2}", shareName, domain, user)); WindowsShare windowsShare = WindowsShare.GetShareByName(shareName.ToString()); if (windowsShare == null) { throw new ShareException(string.Format("Could not find share {0}.", shareName)); } WindowsShare.MethodStatus methodStatus = windowsShare.SetPermission(domain, user, accessMask); if (methodStatus != WindowsShare.MethodStatus.Success) { throw new ShareException(string.Format("Could not set AccessMask {0} for user {1}\\{2} on share {3}", accessMask.ToString(), domain, user, shareName)); } logger.LogInfo(string.Format("Share permissings set for {0}.", shareName)); }