Una forma de conseguir la carpeta del perfil de un usuario específico es mediante el registro de Windows, ya que se almacenan ahí,
pero desconozco si la ruta de dicha clave es la misma en Windows XP, el siguiente código lo he hecho bajo Windows 8 y funciona en Windows 7 también.
Public Class Form1
Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown
Dim SID As String = "S-1-5-21-3344876933-2114507426-1248549232-500"
Dim UserName As String = SID_To_UserName(SID)
Dim ProfilePath As IO.DirectoryInfo = New IO.DirectoryInfo(SID_To_ProfilePath(SID))
Dim LastAccess As DateTime = ProfilePath.LastAccessTime
Dim UserInfo As String = _
String.Format("SID: {1}{0}{0} Username: {2}{0}{0} Profile Path: {3}{0}{0} Last Access: {4}{0}{0}", _
Environment.NewLine, SID, UserName, ProfilePath.FullName, LastAccess)
MessageBox.Show(UserInfo, "User Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
#Region " SID To UserName "
' [ SID To UserName ]
'
' // By Elektro H@cker
'
' Examples:
' MsgBox(SID_To_UserName("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: Administrador
Private Function SID_To_UserName(ByVal SID As String) As String
Dim DomainName As String = New System.Security.Principal.SecurityIdentifier(SID). _
Translate(GetType(System.Security.Principal.NTAccount)).Value
Return DomainName.Substring(DomainName.IndexOf("\") + 1)
End Function
#End Region
#Region " SID To ProfilePath "
' [ SID To ProfilePath ]
'
' // By Elektro H@cker
'
' Examples:
' MsgBox(SID_To_ProfilePath("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: "C:\Users\Administrador"
Private Function SID_To_ProfilePath(ByVal SID As String) As String
Return My.Computer.Registry.GetValue( _
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & SID, _
"ProfileImagePath", _
"Unknown directory")
End Function
#End Region
End Class
Traducción a C# (sin testear):
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class Form1
{
private void Test(object sender, EventArgs e)
{
string SID = "S-1-5-21-3344876933-2114507426-1248549232-500";
string UserName = SID_To_UserName(SID);
IO
.DirectoryInfo ProfilePath
= new IO
.DirectoryInfo(SID_To_ProfilePath
(SID
)); DateTime LastAccess = ProfilePath.LastAccessTime;
string UserInfo = string.Format("SID: {1}{0}{0} Username: {2}{0}{0} Profile Path: {3}{0}{0} Last Access: {4}{0}{0}", Environment.NewLine, SID, UserName, ProfilePath.FullName, LastAccess);
MessageBox.Show(UserInfo, "User Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#region " SID To UserName "
// [ SID To UserName ]
//
// // By Elektro H@cker
//
// Examples:
// MsgBox(SID_To_UserName("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: Administrador
private string SID_To_UserName(string SID)
{
string DomainName
= new System.Security.Principal.SecurityIdentifier(SID
).Translate(typeof(System.Security.Principal.NTAccount)).Value;
return DomainName.Substring(DomainName.IndexOf("\\") + 1);
}
#endregion
#region " SID To ProfilePath "
// [ SID To ProfilePath ]
//
// // By Elektro H@cker
//
// Examples:
// MsgBox(SID_To_ProfilePath("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: "C:\Users\Administrador"
private string SID_To_ProfilePath(string SID)
{
return My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + SID, "ProfileImagePath", "Unknown directory");
}
public Form1()
{
Shown += Test;
}
#endregion
}
//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================