elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Cómo puedo obtener el directorio, fecha modificación por cada cuenta de usuario
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Cómo puedo obtener el directorio, fecha modificación por cada cuenta de usuario  (Leído 2,339 veces)
el_doctor

Desconectado Desconectado

Mensajes: 57


Ver Perfil
Cómo puedo obtener el directorio, fecha modificación por cada cuenta de usuario
« en: 13 Septiembre 2013, 00:02 am »

Hay alguna forma de obtener el path del directorio de cada cuenta de usuario y su modificación con C# he podido obtener el sid de cada usuario pero no se como obtener el path del directorio de cada cuenta. algo así como:

User: localadmin
directory: c:\documment setting\localadmin
last day: 12/09/2013


« Última modificación: 13 Septiembre 2013, 15:15 pm por el_doctor » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: Cómo puedo obtener el directorio, fecha modificación por cada cuenta de usuario
« Respuesta #1 en: 13 Septiembre 2013, 21:57 pm »

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.





Código
  1. Public Class Form1
  2.  
  3.    Private Sub Test(sender As Object, e As EventArgs) Handles MyBase.Shown
  4.  
  5.        Dim SID As String = "S-1-5-21-3344876933-2114507426-1248549232-500"
  6.        Dim UserName As String = SID_To_UserName(SID)
  7.        Dim ProfilePath As IO.DirectoryInfo = New IO.DirectoryInfo(SID_To_ProfilePath(SID))
  8.        Dim LastAccess As DateTime = ProfilePath.LastAccessTime
  9.  
  10.        Dim UserInfo As String = _
  11.        String.Format("SID: {1}{0}{0} Username: {2}{0}{0} Profile Path: {3}{0}{0} Last Access: {4}{0}{0}", _
  12.                      Environment.NewLine, SID, UserName, ProfilePath.FullName, LastAccess)
  13.  
  14.        MessageBox.Show(UserInfo, "User Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
  15.  
  16.    End Sub
  17.  
  18. #Region " SID To UserName "
  19.  
  20.    ' [ SID To UserName ]
  21.    '
  22.    ' // By Elektro H@cker
  23.    '
  24.    ' Examples:
  25.    ' MsgBox(SID_To_UserName("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: Administrador
  26.  
  27.    Private Function SID_To_UserName(ByVal SID As String) As String
  28.  
  29.        Dim DomainName As String = New System.Security.Principal.SecurityIdentifier(SID). _
  30.                                       Translate(GetType(System.Security.Principal.NTAccount)).Value
  31.  
  32.        Return DomainName.Substring(DomainName.IndexOf("\") + 1)
  33.  
  34.    End Function
  35.  
  36. #End Region
  37.  
  38. #Region " SID To ProfilePath "
  39.  
  40.    ' [ SID To ProfilePath ]
  41.    '
  42.    ' // By Elektro H@cker
  43.    '
  44.    ' Examples:
  45.    ' MsgBox(SID_To_ProfilePath("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: "C:\Users\Administrador"
  46.  
  47.    Private Function SID_To_ProfilePath(ByVal SID As String) As String
  48.  
  49.        Return My.Computer.Registry.GetValue( _
  50.               "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & SID, _
  51.               "ProfileImagePath", _
  52.               "Unknown directory")
  53.  
  54.    End Function
  55.  
  56. #End Region
  57.  
  58. End Class


Traducción a C# (sin testear):

Código
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7. public class Form1
  8. {
  9.  
  10.  
  11. private void Test(object sender, EventArgs e)
  12. {
  13. string SID = "S-1-5-21-3344876933-2114507426-1248549232-500";
  14. string UserName = SID_To_UserName(SID);
  15. IO.DirectoryInfo ProfilePath = new IO.DirectoryInfo(SID_To_ProfilePath(SID));
  16. DateTime LastAccess = ProfilePath.LastAccessTime;
  17.  
  18. 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);
  19.  
  20. MessageBox.Show(UserInfo, "User Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  21.  
  22. }
  23.  
  24. #region " SID To UserName "
  25.  
  26. // [ SID To UserName ]
  27. //
  28. // // By Elektro H@cker
  29. //
  30. // Examples:
  31. // MsgBox(SID_To_UserName("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: Administrador
  32.  
  33. private string SID_To_UserName(string SID)
  34. {
  35.  
  36. string DomainName = new System.Security.Principal.SecurityIdentifier(SID).Translate(typeof(System.Security.Principal.NTAccount)).Value;
  37.  
  38. return DomainName.Substring(DomainName.IndexOf("\\") + 1);
  39.  
  40. }
  41.  
  42. #endregion
  43.  
  44. #region " SID To ProfilePath "
  45.  
  46. // [ SID To ProfilePath ]
  47. //
  48. // // By Elektro H@cker
  49. //
  50. // Examples:
  51. // MsgBox(SID_To_ProfilePath("S-1-5-21-3344876933-2114507426-1248549232-500")) ' Result: "C:\Users\Administrador"
  52.  
  53. private string SID_To_ProfilePath(string SID)
  54. {
  55.  
  56. return My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\" + SID, "ProfileImagePath", "Unknown directory");
  57.  
  58. }
  59. public Form1()
  60. {
  61. Shown += Test;
  62. }
  63.  
  64. #endregion
  65.  
  66. }
  67.  
  68. //=======================================================
  69. //Service provided by Telerik (www.telerik.com)
  70. //Conversion powered by NRefactory.
  71. //Twitter: @telerik
  72. //Facebook: facebook.com/telerik
  73. //=======================================================



« Última modificación: 13 Septiembre 2013, 22:04 pm por EleKtro H@cker » En línea

el_doctor

Desconectado Desconectado

Mensajes: 57


Ver Perfil
Re: Cómo puedo obtener el directorio, fecha modificación por cada cuenta de usuario
« Respuesta #2 en: 16 Septiembre 2013, 23:38 pm »

Gracias  EleKtro H@cker, me ha servido la referencia.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines