From ac786f2dbd64e7c6f879ce9db5d28c8e451a783b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=83=E7=82=B9=E5=B7=A5=E5=9D=8A?= Date: Wed, 1 Apr 2020 16:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=94=A8=E6=88=B7=E6=96=87=E4=BB=B6=E5=A4=B9=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E7=AA=97=E4=BD=93=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiMay.Core/Packets/UserFolder.cs | 17 ++++ SiMay.Core/SiMay.Core.csproj | 1 + .../ApplicationService/FileService.cs | 89 ++++++++++++++++++- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 SiMay.Core/Packets/UserFolder.cs diff --git a/SiMay.Core/Packets/UserFolder.cs b/SiMay.Core/Packets/UserFolder.cs new file mode 100644 index 0000000..66fbc95 --- /dev/null +++ b/SiMay.Core/Packets/UserFolder.cs @@ -0,0 +1,17 @@ +using SiMay.ReflectCache; + +namespace SiMay.Core.Packets +{ + public class UserFolder : EntitySerializerBase + { + public string UserName { get; set; } + public string USID { get; set; } + public UserShellFolders[] UserShellFolders { get; set; } + } + + public class UserShellFolders : EntitySerializerBase + { + public string Name { get; set; } + public string Path { get; set; } + } +} diff --git a/SiMay.Core/SiMay.Core.csproj b/SiMay.Core/SiMay.Core.csproj index 42a241c..28ea631 100644 --- a/SiMay.Core/SiMay.Core.csproj +++ b/SiMay.Core/SiMay.Core.csproj @@ -151,6 +151,7 @@ + diff --git a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs index 6f0e1c7..088f129 100644 --- a/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs +++ b/SiMay.RemoteClient.NewCore/ApplicationService/FileService.cs @@ -1,4 +1,5 @@ -using SiMay.Basic; +using Microsoft.Win32; +using SiMay.Basic; using SiMay.Core; using SiMay.Core.Common; using SiMay.Core.Enums; @@ -481,6 +482,55 @@ namespace SiMay.ServiceCore public void RedirtionHandler(TcpSocketSaeaSession session) { var pack = GetMessageEntity(session); + var sessions = UserTrunkContext.UserTrunkContextInstance.GetSessionItems() + .Select(c => new SiMay.Core.Packets.SysManager.SessionItem() + { + UserName = c.UserName, + SessionId = c.SessionId, + SessionState = c.SessionState, + WindowStationName = c.WindowStationName, + HasUserProcess = c.HasUserProcess + }) + .ToArray(); + foreach (var sessionItem in sessions) + { + if (sessionItem.SessionState == 1 && sessionItem.UserName.ToLower() != "system") + { + List userFolders = GetUserFolderPath(); + foreach (var item in userFolders) + { + if (item.UserName == sessionItem.UserName) + { + string strFolderName = "Desktop"; + if (pack.SpecialFolder == Environment.SpecialFolder.MyDocuments) + { + strFolderName = "Personal"; + } + else if (pack.SpecialFolder == Environment.SpecialFolder.MyMusic) + { + strFolderName = "My Music"; + } + else if (pack.SpecialFolder == Environment.SpecialFolder.MyPictures) + { + strFolderName = "My Pictures"; + } + else if (pack.SpecialFolder == Environment.SpecialFolder.MyVideos) + { + strFolderName = "My Video"; + } + List userShellFolders = item.UserShellFolders.ToList(); + foreach (var usfItem in userShellFolders) + { + if (usfItem.Name == strFolderName) + { + this.GetFileListHandler(usfItem.Path); + return; + } + } + } + } + } + } this.GetFileListHandler(Environment.GetFolderPath(pack.SpecialFolder)); } @@ -660,5 +710,42 @@ namespace SiMay.ServiceCore return fileLst; } + + public static List GetUserFolderPath() + { + var userFolder = new List(); + using (RegistryKey regBaseKey = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry32)) + { + foreach (string strUserKey in regBaseKey.GetSubKeyNames()) + { + if (strUserKey.ToLower().StartsWith("s-1-5-21") && !strUserKey.ToLower().Contains("classes")) + { + RegistryKey regUserKey = regBaseKey.OpenSubKey(strUserKey); + RegistryKey regEnvironment = regUserKey.OpenSubKey("Volatile Environment"); + string strUserName = (string)regEnvironment.GetValue("USERNAME", string.Empty); + if (strUserName != string.Empty) + { + RegistryKey regShellFolders = regUserKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"); + var userShellFolders = new List(); + foreach (string strKeyName in regShellFolders.GetValueNames()) + { + userShellFolders.Add(new UserShellFolders() + { + Name = strKeyName, + Path = (string)regShellFolders.GetValue(strKeyName, string.Empty) + }); + } + userFolder.Add(new UserFolder() + { + UserName = strUserName, + USID = strUserKey, + UserShellFolders = userShellFolders.ToArray() + }); + } + } + } + } + return userFolder; + } } } \ No newline at end of file -- Gitee