2012-01-13 2 views
2

ブラウザプラグインを含むIISのaspxページを使用して、ターミナルサーバーでローカルスキャナを使用できるようにしようとしています。プラグインはファイルをスキャンして、サーバーにファイルをアップロードするaspxページにデータを渡すことができます。ターミナルサービスユーザーのドキュメントフォルダを見つける

私はHttpContext.Current.User.Identity.Nameを使用して、リモートユーザーの名前を含む文字列を取得しています。ターミナルサーバー上でユーザーのドキュメントフォルダを検索するにはどうすればよいですか?

答えて

0

少し進歩しました。ここでは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#は私の母国語ではありませんが。これを達成する方法はおそらく鈍いものではないでしょう。しかし、の仕事をします。