Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Visual Basic: Como leer el serial del disco duro.

Estas en el tema de Visual Basic: Como leer el serial del disco duro. en el foro de Visual Basic clásico en Foros del Web. Hola chicos. Aquí estoy de nuevo para hacer otra pregunta loca (como alguien me dijo por ahí). Mi duda es como obtener el Serial del ...
  #1 (permalink)  
Antiguo 02/09/2002, 23:04
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Visual Basic: Como leer el serial del disco duro.

Hola chicos.

Aquí estoy de nuevo para hacer otra pregunta loca (como alguien me dijo por ahí).

Mi duda es como obtener el Serial del Disco duro (existe un volumen y un serial, aparte de otros datos claro está), a través de funciones o API de Windows, o como sea.

Ojalá alguien pueda ayudarme.

Saludos.
;)
  #2 (permalink)  
Antiguo 03/09/2002, 05:07
jcl
 
Fecha de Ingreso: enero-2002
Mensajes: 673
Antigüedad: 22 años, 4 meses
Puntos: 1
Re: Visual Basic: Como leer el serial del disco duro.

Primero:


Public Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

Después:


Public Function GetVolumeSerials() As Long
plpVolumeNameBuffer = ""
pnVolumeNameSize = 0
plpVolumeSerialNumber = 0
plpMaximumComponentLength = 0
plpFileSystemFlags = 0
plpFileSystemNameBuffer = ""
pnFileSystemNameSize = 0

plpRootPathName = "C:\"
Dim Res
Res = GetVolumeInformation(plpRootPathName, _
plpVolumeNameBuffer, _
pnVolumeNameSize, _
plpVolumeSerialNumber, _
plpMaximumComponentLength, _
plpFileSystemFlags, _
plpFileSystemNameBuffer, _
pnFileSystemNameSize)

GetVolumeSerials = plpVolumeSerialNumber

End Function


Sólo tienes que cortar y pegar este código. Luego en el lugar apropiado llamas la función con algo así:

Dim Serial as logn

Serial = GetVolumeSerials

Y allí tendrás lo que buscas.
  #3 (permalink)  
Antiguo 03/09/2002, 21:43
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Re: Visual Basic: Como leer el serial del disco duro.

Gracias JCL, probé lo que me dijiste y resulta que me devuelve 0, ¿estaré haciendo algo mal?.

Hice exactamente lo que dijiste, copie el código y todo, pero no me devuelve nada (bueno como dije me devuelve 0):(

Ojala me puedas ayudar otro poco.

Gracias de todos modos.

Saludos.
;)
  #4 (permalink)  
Antiguo 04/09/2002, 02:34
 
Fecha de Ingreso: abril-2002
Mensajes: 438
Antigüedad: 22 años
Puntos: 2
Re: Visual Basic: Como leer el serial del disco duro.

Hola,

Se me ocurre otra manera de hacerlo, con el siempre recurrido en momentos de necesidad FileSystemObject. Con él después haces un set del objeto Drive con getDriver y finalmente usas su propiedad serialNumber. Algo del palo:

Private Sub saberNumSerieDiscoDuro()
Dim fso As New Scripting.FileSystemObject
Dim dr As Scripting.Drive
Set dr = fso.GetDrive("c:")
msgBox dr.SerialNumber
End Sub

Acuérdate de marcar en referencias la "Microsoft Scripting Runtime" necesaria para poder usar el FileSystemObject.

Saludos.
  #5 (permalink)  
Antiguo 04/09/2002, 04:23
jcl
 
Fecha de Ingreso: enero-2002
Mensajes: 673
Antigüedad: 22 años, 4 meses
Puntos: 1
Re: Visual Basic: Como leer el serial del disco duro.

Lo que puedo recomendarte es revisar si alguna variable haya cambiado de nombre; o los valores por defecto no se hayan copiado bien, pero eso lo tome "tal cual" de un sistema que tengo en funcionamiento actual mente

De todas maneras, revisaré y cualquier cosa te digo. Fíjate que si lo conbinas con los controles DriveListBox, DirLisBox y FileListBox, puedes tener la facilidad de ubicar unidades, path y archivos.

Saludos.
  #6 (permalink)  
Antiguo 04/09/2002, 04:34
jcl
 
Fecha de Ingreso: enero-2002
Mensajes: 673
Antigüedad: 22 años, 4 meses
Puntos: 1
Re: Visual Basic: Como leer el serial del disco duro.

Hola "hchris",

Hagamos algo mejor y más seguro. Tu me envías tu dirección de correos al mío, lo cual puedes hacer si accedes a mi perfil.

Luego yo te envío en formato (.zip) un ejemplo con ese mismo código funcionando. ¿Te parece?

Saludos.
  #7 (permalink)  
Antiguo 07/09/2002, 22:49
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Re: Visual Basic: Como leer el serial del disco duro.

Hola chicos, perdón la tardanza pero he estado más que ocupado y no he podido acceder al foro.

Primero que nada les agradeszco los aportes.

Voy a probar con lo que me dijo sndsdlm . En cuanto a JCL , el problema parece no ser el código que me enviaste, dado que lo búsque en varios lugares y todos tenían el mismo problema. De tanto buscar encontré una información referente al GetVolumeInformation de la Microsoft y es que viene con problemas, ya que no devuelve el número de serie sino que entrega un 0 (cero), el informe es el siguiente :

...
BUG: GetVolumeInformation Doesn"t Return Volume Serial Number of Remote Drives on Windows
The information in this article applies to:
Microsoft Win32 Application Programming Interface (API), when used with:
the operating system: Microsoft Windows 95
the operating system: Microsoft Windows 98
the operating system: Microsoft Windows Millennium Edition
Symptoms
Win32 programs use GetVolumeInformation() to retrieve information about local and remote volumes. On Microsoft Windows 95, Microsoft Windows 98, and Microsoft Windows Millennium Edition (Me) GetVolumeInformation() does not retrieve the actual serial number of remote volumes, but always returns zero for the volume serial number.
Resolution
To obtain the volume serial number of a remote volume, open a file on the remote volume and use GetFileInformationByHandle(). Part of the returned information is the serial number of the volume on which the file is located. This strategy works as long as there is a file on the remote volume that can be opened. The following sample code demonstrates how to do this:
...

  #8 (permalink)  
Antiguo 07/09/2002, 22:52
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Re: Visual Basic: Como leer el serial del disco duro.


#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <stdio.h>

BOOL GetVolumeSerialNumber (LPCSTR pszRootPathName, DWORD *pdwSerialNum);

void main (int argc, char **argv)
{
BOOL fResult;
char *pszDriveName;

// volume information we want to collect
char szVolName[MAX_PATH];
char szFileSysName[80];
DWORD dwSerialNumber;
DWORD dwMaxComponentLen;
DWORD dwFileSysFlags;


// Validate command-line arguments.
if (argc != 2)
{
printf("usage: %s drive\n\tdrive = C:\\, \\\\svr\\share\\\n",
argv[0]);
printf("\tnote: the trailing backslash is needed\n");
return;
}

pszDriveName = argv[1];

fResult = GetVolumeInformation(pszDriveName, szVolName, MAX_PATH,
&dwSerialNumber, &dwMaxComponentLen,
&dwFileSysFlags, szFileSysName, 80);
if (fResult)
{
// If the serial number wasn't returned, try to get it a
// different way.
if (dwSerialNumber == 0)
GetVolumeSerialNumber (pszDriveName, &dwSerialNumber);

printf("volume name = %s\n", szVolName);
printf("serial number = %#lx\n", dwSerialNumber);
}
else
printf("could not get info for %s, error = %lu\n",
pszDriveName, GetLastError());
}


/*


  #9 (permalink)  
Antiguo 07/09/2002, 22:54
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Re: Visual Basic: Como leer el serial del disco duro.


GetVolumeSerialNumber( pszRootPathName, pdwSerialNum )

Retrieves the serial number of a local or remote volume.

Parameters
pszRootPathName
The volume to get the serial number of. Must be specified as
one of:
A drive letter, colon and trailing backslash. C:\
A UNC name with trailing backslash. \\svr\share\

pdwSerialNum
A pointer to a DWORD that will contain the serial number when
the function returns. Note: the caller must allocate the memory
for this parameter.

Return value
Returns TRUE if it successfully retrieves a volume serial number, or
FALSE if it can't.
*/
BOOL GetVolumeSerialNumber (LPCSTR pszRootPathName, DWORD *pdwSerialNum)
{
BOOL bReturn = FALSE; // Assume that we haven't get the serial number,
// then set it to true if we do get it.

HANDLE hFile;
BY_HANDLE_FILE_INFORMATION bhFileInfo;

HANDLE hFileFind;
WIN32_FIND_DATA wfdFileData;
char szFindFileName[MAX_PATH];


/*
Search for any file that we can open and retrieve information about.
That information will include the serial number of the volume on
which the file resides.
*/
lstrcpy (szFindFileName, pszRootPathName);
lstrcat (szFindFileName, "*");

hFileFind = FindFirstFile (szFindFileName, &wfdFileData);
if (INVALID_HANDLE_VALUE == hFileFind)
goto EXIT_DONE;

do
{
/* Make sure that we've found a file and not a directory */
if (!(wfdFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
  #10 (permalink)  
Antiguo 07/09/2002, 22:57
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Re: Visual Basic: Como leer el serial del disco duro.


/*
Found a file. Now, use the full path to open the file and get
information about it. This information includes the serial
number of the volume on which the file resides. If we do get
the info, we can bail out because we're done.

If we can't open this file, look for another one we can open.
*/
lstrcpy (szFindFileName+lstrlen(pszRootPathName),
wfdFileData.cFileName);

hFile = CreateFile (szFindFileName,
0, // don't need to open for read or write
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE != hFile)
{
bReturn = GetFileInformationByHandle(hFile, &bhFileInfo);
CloseHandle(hFile);

if (bReturn)
break;
}
}
}
while (FindNextFile(hFileFind, &wfdFileData));
CloseHandle (hFileFind); /* don't need the find handle anymore */

/* If we have the serial number, return it to the caller */
if (bReturn )
{
__try
{
*pdwSerialNum = bhFileInfo.dwVolumeSerialNumber;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
SetLastError (ERROR_INVALID_PARAMETER);
bReturn = FALSE;
}
}

EXIT_DONE:
return (bReturn);
}
Status
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


UFFF, que me salio largo... En cuanto tenga el código migrado a visual se los envío...
si a alguien se le ocurre otra ingeniosa idea no dejen de avisarme...

Saludos Amigos.
  #11 (permalink)  
Antiguo 07/09/2002, 23:26
 
Fecha de Ingreso: abril-2002
Mensajes: 20
Antigüedad: 22 años
Puntos: 0
Re: Visual Basic: Como leer el serial del disco duro.

Pero que bieeen !!!.

SDNSDLM acabo de probar tu código y funcionó al pelo... te agradezco mucho tu ayuda y también a JCL . ;)

Gracias de nuevo y Saludos.

Christian.
  #12 (permalink)  
Antiguo 03/02/2009, 12:32
 
Fecha de Ingreso: marzo-2008
Mensajes: 37
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Visual Basic: Como leer el serial del disco duro.

Hola me podrias enviar el codigo a mi correo ojala puedas gracias

[email protected]
  #13 (permalink)  
Antiguo 03/02/2009, 12:41
Colaborador
 
Fecha de Ingreso: enero-2008
Ubicación: Unas veces aquí, otras veces allí
Mensajes: 1.482
Antigüedad: 16 años, 3 meses
Puntos: 37
Respuesta: Visual Basic: Como leer el serial del disco duro.

Cita:
Iniciado por HalleyR Ver Mensaje
Hola me podrias enviar el codigo a mi correo ojala puedas gracias

[email protected]

No creo que después de seis años y medio esté ahí todavía para enviarte el código a tu correo.

De todas formas el código está ahí ¿porqué no lo copias?

  #14 (permalink)  
Antiguo 03/02/2009, 14:51
Avatar de seba123neo  
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Respuesta: Visual Basic: Como leer el serial del disco duro.

Cita:
Iniciado por Avellaneda Ver Mensaje

No creo que después de seis años y medio esté ahí todavía para enviarte el código a tu correo.

De todas formas el código está ahí ¿porqué no lo copias?

jaja creo que el usuario no existe mas...
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein
  #15 (permalink)  
Antiguo 15/06/2011, 11:48
 
Fecha de Ingreso: junio-2011
Mensajes: 1
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Re: Visual Basic: Como leer el serial del disco duro.

Cita:
Iniciado por sdnsdlm Ver Mensaje
Hola,

Se me ocurre otra manera de hacerlo, con el siempre recurrido en momentos de necesidad FileSystemObject. Con él después haces un set del objeto Drive con getDriver y finalmente usas su propiedad serialNumber. Algo del palo:

Private Sub saberNumSerieDiscoDuro()
Dim fso As New Scripting.FileSystemObject
Dim dr As Scripting.Drive
Set dr = fso.GetDrive("c:")
msgBox dr.SerialNumber
End Sub

Acuérdate de marcar en referencias la "Microsoft Scripting Runtime" necesaria para poder usar el FileSystemObject.

Saludos.
Disculpa mi ignorancia que significa &quot no lo encuentro como referencia
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 21:19.