Foros del Web » Programación para mayores de 30 ;) » .NET »

Serial disco duro SATA

Estas en el tema de Serial disco duro SATA en el foro de .NET en Foros del Web. Hola buen dia!!! Alguien podria ayudarme?? necesito obtener el serial de un disco duro SATA ya he probado varias cosas, con el win32-PhysicalMedia pero solo ...
  #1 (permalink)  
Antiguo 17/07/2009, 17:33
 
Fecha de Ingreso: mayo-2009
Ubicación: Mexico
Mensajes: 14
Antigüedad: 15 años
Puntos: 0
Serial disco duro SATA

Hola buen dia!!!

Alguien podria ayudarme?? necesito obtener el serial de un disco duro SATA ya he probado varias cosas, con el win32-PhysicalMedia pero solo me sirve para otros discos duros pero no para SATA, eh probado con win32_DiskDrive y para obtenerlo escribo disco.signature pero me arroja el numero de volumen no el serial fisico del disco duro, estoy trabajando con visual studio 2005 (vb)

Cualquier ayuda será bien recibida!!!
Gracias!!
  #2 (permalink)  
Antiguo 17/07/2009, 18:29
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Serial disco duro SATA

Te la paso porque realmente nunca tuve la oportunidad de usarla por completo, aprovéchala:

Código:
/* (c) Febrero 2005 - Maycol Alvarez
 * Caracas, Venezuela
 * SINTAXIS DE .NET FRAMEWORK 1.1
 * DriveInfo: encapsula operaciones básicas para obtener datos
 * precisos sobre las unidades de disco
*/
using System;
/// <summary>
/// Devuelve información sobre las unidades de disco. (C) 2005, Maycol Alvarez
/// </summary>
[System.Diagnostics.DebuggerStepThrough()]
public sealed class DriveInfo
{
	#region "toda la API"
	[System.Runtime.InteropServices.DllImport("kernel32"),System.ComponentModel.Browsable(false)]
	private static extern int GetDriveType (string nDrive);
	[System.Runtime.InteropServices.DllImport("kernel32")]
	private static extern int GetDiskFreeSpaceEx(string lpRootPathName,ref long lpFreeBytesAvailableToCaller,ref long lpTotalNumberOfBytes,ref long lpTotalNumberOfFreeBytes);
	[System.Runtime.InteropServices.DllImport("kernel32")]
	private static extern int GetVolumeInformation(string lpRootPathName,byte[] lpVolumeNameBuffer, int nVolumeNameSize,ref int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags,byte[] lpFileSystemNameBuffer,int nFileSystemNameSize);
	[System.Runtime.InteropServices.DllImport("kernel32")]
	private static extern int GetVolumeInformation(string lpRootPathName,byte[] lpVolumeNameBuffer, int nVolumeNameSize,int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags,byte[] lpFileSystemNameBuffer,int nFileSystemNameSize);
    
	/// <summary>
	/// Tipo o estado de la unidad
	/// </summary>
	public enum DriveType
	{
		/// <summary>
		/// Irreconocible
		/// </summary>
		DRIVE_UNKNOWN=0,
		/// <summary>
		/// Ruta no valida
		/// </summary>
		DRIVE_NO_ROOT_DIR,
		Removible,
		/// <summary>
		/// Discos Duros
		/// </summary>
		Drive_Fixed,
		Remoto,
		CDROM,
		Ram_Disk,
	};
	/// <summary>
	/// Especifica las unidades de medida de un disco
	/// </summary>
	public enum DriveMetric
	{
		Bits,
		Byte,
		Kilobyte,
		Megabyte,
		Gigabyte
	};
	#endregion
	#region "interfaz principal"
	private DriveType _dt;
	private string _dr;
	/// <summary>
	/// Inicializa una nueva instancia de Driveinfo.
	/// </summary>
	/// <param name="drive">Unidad en el formato: ('letra unidad':\)</param>
	public DriveInfo(string drive):this(drive,true)
	{
	}
	/// <summary>
	/// Inicializa una nueva instancia de Driveinfo.
	/// </summary>
	/// <param name="drive">Unidad en el formato: ('letra unidad':\)</param>
	private DriveInfo(string drive,bool ex)
	{
		int i = GetDriveType(drive);
		if ((i == 1)&&ex)
		{
			throw new ArgumentException("no es una unidad o ruta valida");
		}
		_dt = (DriveType)i;
		if (drive.EndsWith(@"\"))
		{
			_dr = drive;
		}
		else
		{
			_dr = drive + @"\";
		}
	}
	/// <summary>
	/// Obtiene el tipo de unidad.
	/// </summary>
	public DriveInfo.DriveType InfoType 
	{
		get
		{
			return _dt;
		}
	}
	/// <summary>
	/// Devuelve la ruta de la unidad
	/// </summary>
	public string Drive 
	{
		get
		{
			return _dr;
		}
	}
	/// <summary>
	/// Obtiene una nueva instancia de DirectoryInfo de la unidad
	/// </summary>
	/// <returns>Instancia de System.IO.DirectoryInfo</returns>
	public System.IO.DirectoryInfo GetDirectoryInfo()
	{
		return new System.IO.DirectoryInfo(_dr);
	}
	/// <summary>
	/// Recupera las unidades de este equipo en instancias de DriveInfo.
	/// </summary>
	/// <returns>matriz unidimensional</returns>
	[System.Diagnostics.DebuggerStepThrough()]
	public static DriveInfo[] GetLogicalDrivesInfo()
	{
		string[] di = System.IO.Directory.GetLogicalDrives();
		DriveInfo[] rdi = new DriveInfo[di.Length];
		for(int i=0;i<di.Length;i++)
		{
			rdi[i] = new DriveInfo(di[i],false);
		}
		return rdi;
	}
	#endregion
	#region "FreeDiskSpace"
	/// <summary>
	/// Obtiene el total de bytes de la unidad
	/// </summary>
	/// <returns>si falla produce Exception</returns>
	public long GetTotalBytes()
	{
		long disponibles=0,totales=0,libres=0;
		int i;
		i = GetDiskFreeSpaceEx(_dr,ref disponibles,ref totales,ref libres);
		if (i != 0)
		{
			return totales;
		}
		else
		{
			throw new Exception("no se puede determinar");
		}
	}
	/// <summary>
	/// Obtiene el total de bytes de la unidad
	/// </summary>
	/// <param name="exp">Determina en que unidad de medida se obtendrá</param>
	/// <returns>si falla produce Exception</returns>
	public double GetTotalBytes(DriveInfo.DriveMetric exp)
	{
		return ConverDriveMetric(GetTotalBytes(),exp);
	}
	/// <summary>
	/// Obtiene el total de bytes disponibles de la unidad
	/// </summary>
	/// <returns>si falla produce Exception</returns>
	public long GetAvailableTotalFreeBytes()
	{
		long disponibles=0,totales=0,libres=0;
		int i;
		i = GetDiskFreeSpaceEx(_dr,ref disponibles,ref totales,ref libres);
		if (i != 0)
		{
			return disponibles;
		}
		else
		{
			throw new Exception("no se puede determinar");
		}
	}
	/// <summary>
	/// Obtiene el total de bytes disponibles de la unidad
	/// </summary>
	/// <param name="exp">Determina la unidad de medida en que se obtendrá</param>
	/// <returns>si falla produce Exception</returns>
	public double GetAvailableTotalFreeBytes(DriveInfo.DriveMetric exp)
	{
		return ConverDriveMetric(GetAvailableTotalFreeBytes(),exp);
	}
	/// <summary>
	/// Obtiene el total de bytes libres de la unidad
	/// </summary>
	/// <returns>si falla produce Exception</returns>
	public long GetTotalFreeBytes()
	{
		long disponibles=0,totales=0,libres=0;
		int i;
		i = GetDiskFreeSpaceEx(_dr,ref disponibles,ref totales,ref libres);
		if (i != 0)
		{
			return libres;
		}
		else
		{
			throw new Exception("no se puede determinar");
		}
	}
	/// <summary>
	/// Obtiene el total de bytes libres de la unidad
	/// </summary>
	/// <param name="exp">Determina la unidad de medida en que se obtendrá</param>
	/// <returns>si falla produce Exception</returns>
	public double GetTotalFreeBytes(DriveInfo.DriveMetric exp)
	{
		return ConverDriveMetric(GetTotalFreeBytes(),exp);
	}
	/// <summary>
	/// Obtiene el total de bytes usados en la unidad
	/// </summary>
	/// <returns>si falla produce Exception</returns>
	public long GetTotalUsedBytes()
	{
		long disponibles=0,totales=0,libres=0;
		int i;
		i = GetDiskFreeSpaceEx(_dr,ref disponibles,ref totales,ref libres);
		if (i != 0)
		{
			return totales - libres;
		}
		else
		{
			throw new Exception("no se puede determinar");
		}
	}
	/// <summary>
	/// Obtiene el total de bytes usados en la unidad
	/// </summary>
	/// <param name="exp">Determina la unidad de medida en que se obtendrá</param>
	/// <returns>si falla produce Exception</returns>
	public double GetTotalUsedBytes(DriveInfo.DriveMetric exp)
	{
		return ConverDriveMetric(GetTotalUsedBytes(),exp);
	}
	/// <summary>
	/// Obtiene una matriz unidimencional con: total de bytes libres disponibles,total de bytes,total de bytes libres, total de bytes usados
	/// </summary>
	/// <returns>matriz unidimensional de 4 elementos</returns>
	public long[] GetFreeSpace()
	{
		long disponibles=0,totales=0,libres=0;
		int i;
		i = GetDiskFreeSpaceEx(_dr,ref disponibles,ref totales,ref libres);
		if (i != 0)
		{
			return new long[4]{disponibles,totales,libres,totales-libres};
		}
		else
		{
			throw new Exception("no se puede determinar");
		}
	}
	/// <summary>
	/// Convierte un valor expresado en bytes a otras medidas
	/// </summary>
	/// <param name="bytes">valor espresado en bytes</param>
	/// <param name="exp">medida a convetir</param>
	/// <returns>valor convertido de bytes a exp</returns>
	[System.Diagnostics.DebuggerStepThrough()]
	public static double ConverDriveMetric(long bytes,DriveInfo.DriveMetric exp)
	{
		switch(exp)
		{
			case DriveMetric.Bits:
                return bytes*8;
			case DriveMetric.Kilobyte:
				return bytes/1024;
			case DriveMetric.Megabyte:
				return bytes/1024/1024;
			case DriveMetric.Gigabyte:
				return bytes/1024/1024/1024;
			default:
				return bytes;
		}
	}
	#endregion
	#region "VolumeInfo"
	/// <summary>
	/// Obtiene el nombre del volumen de la unidad
	/// </summary>
	/// <returns>si falla devuelve null</returns>
	public string GetVolumeName()
	{
		int i;
		byte[] volumenamebuffer = new byte[255];
		i = GetVolumeInformation(_dr,volumenamebuffer,volumenamebuffer.Length,0,0,0,null,0);
		if (i!=0)
		{
			return System.Text.Encoding.ASCII.GetString(volumenamebuffer).TrimEnd((char)0);
		}
		return null;
	}
	/// <summary>
	/// Obtiene el tipo de unidad
	/// </summary>
	/// <returns>si falla devuelve null</returns>
	public string GetSystemVolumeName()
	{
		int i;
		byte[] systemnamebuffer = new byte[255];
		i = GetVolumeInformation(_dr,null,0,0,0,0,systemnamebuffer,systemnamebuffer.Length);
		if (i!=0)
		{
			return System.Text.Encoding.ASCII.GetString(systemnamebuffer).TrimEnd((char)0);
		}
		return null;
	}
	/// <summary>
	/// Obtiene el serial del volumen de la unidad
	/// </summary>
	/// <returns>si falla devuelve 0</returns>
	public int GetVolumeSerialNumber()
	{
		int i,sn=0;
		i = GetVolumeInformation(_dr,null,0,ref sn,0,0,null,0);
		if (i!=0)
		{
			return sn;
		}
		return 0;
	}
	/// <summary>
	/// Obtiene una matriz de object con: nombre del volumen,serial del volumen,tipo de volumen ; de la unidad
	/// </summary>
	/// <returns>matriz unidimensonal object de 3 elementos [string,int,string]</returns>
	public object[] GetVolumeInfo()
	{		
		int i,sn=0;
		byte[] volumenamebuffer = new byte[255];
		byte[] systemnamebuffer = new byte[255];
		i = GetVolumeInformation(_dr,volumenamebuffer,volumenamebuffer.Length,ref sn,0,0,systemnamebuffer,systemnamebuffer.Length);
		if (i!=0)
		{
			return new object[3]{System.Text.Encoding.ASCII.GetString(volumenamebuffer).TrimEnd((char)0),sn,System.Text.Encoding.ASCII.GetString(systemnamebuffer).TrimEnd((char)0)};
		}
		return null;
	}
	#endregion
}
uso:

DriveInfo c = new DriveInfo("c:");
MessageBox.Show(c.GetVolumeSerialNumber().ToString ());

Última edición por maycolalvarez; 17/07/2009 a las 18:40 Razón: Como se usa
  #3 (permalink)  
Antiguo 17/07/2009, 18:47
 
Fecha de Ingreso: mayo-2009
Ubicación: Mexico
Mensajes: 14
Antigüedad: 15 años
Puntos: 0
Respuesta: Serial disco duro SATA

maycolalvarez:
Gracias por tu respuesta... voy a probarlo y te aviso
  #4 (permalink)  
Antiguo 18/07/2009, 00:52
 
Fecha de Ingreso: mayo-2009
Ubicación: Mexico
Mensajes: 14
Antigüedad: 15 años
Puntos: 0
Respuesta: Serial disco duro SATA

Gracias.. pero no obtuve lo que necesitaba me sigue mostrando un blanco

si alguien mas que pueda ayudarme se los agradeceria.. o alguna pag. donde pueda yo consulta...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:10.