查找终端服务用户的文档文件夹

发布于 2024-12-27 01:12:48 字数 181 浏览 0 评论 0原文

我试图允许用户通过包含浏览器插件的 IIS aspx 页面将本地扫描仪与终端服务器一起使用。该插件可以扫描文件并将数据传递到 aspx 页面,该页面将文件上传到服务器。

我正在使用 HttpContext.Current.User.Identity.Name 来获取包含远程用户名称的字符串。如何在终端服务器上找到用户的文档文件夹?

I'm trying to allow users to use their local scanners with a Terminal Server via an IIS aspx page containing a browser plugin. The plugin can scan files and pass the data to an aspx page which uploads files to the server.

I'm using HttpContext.Current.User.Identity.Name to get a string containing the name of the remote user. How can I find the user's documents folder on the terminal server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2025-01-03 01:12:48

取得了一点进步。以下是使用 Powershell 查找已知用户名路径的方法:

$user = Get-WmiObject Win32_UserAccount | Where-Object { $_.Name -eq 'known_username' }
cd 'HKLM:\software\Microsoft\Windows NT\CurrentVersion\ProfileList'
$key = Get-Item $user.SID
$saveLocation = $key.GetValue("ProfileImagePath")

这是 C# 版本:

string loginName = HttpContext.Current.User.Identity.Name;
Regex r = new Regex(@"\w+[\\]");
string userName = r.Replace(loginName, "");
throw new System.ArgumentException("Debug: '" + HttpContext.Current.User.Identity.IsAuthenticated.ToString() +"'", "userName");
SelectQuery sQuery = new SelectQuery("Win32_UserAccount", "name='" + userName + "'");
ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQuery);
string sid = "";
foreach (ManagementObject mObject in mSearcher.Get()) 
{
    sid = mObject["SID"].ToString();
    break; //mSearcher.Get() is not indexable. Behold the hackyness!
}
string saveLocation = Microsoft.Win32.Registry.GetValue(
    "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + sid,
    "ProfileImagePath", null).ToString();

C# 不是我的母语;可能有一些不那么直率的方法可以实现这一点。但它确实有效。

Made a bit of progress. Here's a way to find a the path for a known username using Powershell:

$user = Get-WmiObject Win32_UserAccount | Where-Object { $_.Name -eq 'known_username' }
cd 'HKLM:\software\Microsoft\Windows NT\CurrentVersion\ProfileList'
$key = Get-Item $user.SID
$saveLocation = $key.GetValue("ProfileImagePath")

Here's the C# version:

string loginName = HttpContext.Current.User.Identity.Name;
Regex r = new Regex(@"\w+[\\]");
string userName = r.Replace(loginName, "");
throw new System.ArgumentException("Debug: '" + HttpContext.Current.User.Identity.IsAuthenticated.ToString() +"'", "userName");
SelectQuery sQuery = new SelectQuery("Win32_UserAccount", "name='" + userName + "'");
ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQuery);
string sid = "";
foreach (ManagementObject mObject in mSearcher.Get()) 
{
    sid = mObject["SID"].ToString();
    break; //mSearcher.Get() is not indexable. Behold the hackyness!
}
string saveLocation = Microsoft.Win32.Registry.GetValue(
    "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + sid,
    "ProfileImagePath", null).ToString();

C# is not my native tongue; there are probably methods of accomplishing this that are less blunt. But it does work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文