Pular para o conteúdo principal

Postagens

Mostrando postagens de Maio, 2011

Retornando o Número de Série do HD em C - Linux

#include stdio.h
#include fcntl.h
#include string.h
#include linux/hdreg.h


char* retornaID(char *drive){
  struct hd_driveid hd;
  int ide;
  ide=open(drive,O_RDONLY);
  ioctl (ide,HDIO_GET_IDENTITY,&hd);
  char *did = (char *) malloc(strlen(hd.serial_no) + 1);
  strncpy(did,hd.serial_no, sizeof(hd.serial_no));
  return did;
}


int main()
{
  char *drive = "/dev/hda";
  printf("ID: %s\n", retornaID(drive));
}

Retornando o Número de Série do HD em C - Windows

#include iostream.h
#include stdio.h
#include windows.h


DWORD retornaID(char *drive){
      BOOL fResult;
      char *pszDriveName;

      char szVolName[MAX_PATH];
      char szFileSysName[80];
      DWORD dwSerialNumber;
      DWORD dwMaxComponentLen;
      DWORD dwFileSysFlags;

      pszDriveName = drive;

      fResult = GetVolumeInformation(pszDriveName, szVolName, MAX_PATH,
      &dwSerialNumber, &dwMaxComponentLen,
      &dwFileSysFlags, szFileSysName, 80);

      return dwSerialNumber;
}


int main (int argc, char **argv)
{
    char *drive = "c:\\";
    printf("ID: %#ld\n", retornaID(drive));
    system("PAUSE"); 
}