Link to home
Create AccountLog in
Avatar of KingSencat
KingSencat

asked on

Volume Serial Changer Project in C ++ ( Working ) Please read

I have found this volume serial changer SOURCE CODE on the net, seems to work perfect . The thing is that i want to change my serial number without any human input, just to double click the compliled.exe and changes automatically my hard disk c:\ volume serial number to 123456789 and then restart automatcially so the changes take effect. Can you please DOWNLOAD THE Volume Serial Changer Project maded in C ++  and tell me what i have to change to make this possible ?

Here is the zip file .

URL DIRECT DOWNLOAD:
http://dumpplace.com/files/403/VolumeSerial_src.zip

Thanks
Avatar of jkr
jkr
Flag of Germany image

Well, first, you need a compiler to build the application after the changes are made, get Visual C++ Express from http://msdn.microsoft.com/vstudio/express/

Ill take a look at the code while you are downloading.
OK, save the following code as "volser.cpp", start VC++ go to "Tools | Visual Studio Command Prompt", 'cd' to where the file was saved and type

cl.exe volser.cpp
#include <windows.h>
 
#pragma comment(lib,"user32.lib")
 
class DiskSectorRW
{
public:
  virtual bool Open(char *vol) = 0;
  virtual void Close() = 0;
  virtual bool ReadSector(DWORD sector, char *Buffer, int sectorSize = 512) = 0;
  virtual bool WriteSector(DWORD sector, char *buffer, int sectorSize = 512) = 0;
};
 
class DiskSectorWinNT : public DiskSectorRW
{
private:
  HANDLE m_hDisk;
public:
  bool Open(char *vol);
  void Close();
  bool ReadSector (DWORD sector, char *Buffer, int sectorSize = 512);
  bool WriteSector(DWORD sector, char *Buffer, int sectorSize = 512);
};
 
class DiskSectorWin9x : public DiskSectorRW
{
private:
  HANDLE m_hVmm32;
  bool m_bOpened;
  char m_chDrive;
  BYTE m_nDriveNo;
  bool m_bW9xOsr2AndAbove;
  bool m_bUseLocking;
public:
  
  DiskSectorWin9x() : m_bUseLocking(false) { }
  bool Open(char *vol);
  void Close();
  
  bool ReadSector (DWORD sector, char *Buffer, int sectorSize = 512);
  bool WriteSector(DWORD sector, char *Buffer, int sectorSize = 512);
  
  static bool LockLogicalVolume (HANDLE hVWin32, BYTE   bDriveNum, BYTE   bLockLevel, WORD wPermissions);
  static bool UnlockLogicalVolume(HANDLE hVWin32, BYTE bDriveNum);  
 
  static bool ReadLogicalSectors (HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD wSectors, LPBYTE lpSectBuff);
  static bool WriteLogicalSectors (HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD   wSectors, LPBYTE lpSectBuff);
 
  static bool NewReadSectors(HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD   wSectors, LPBYTE lpSectBuff);
  static bool NewWriteSectors(HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD   wSectors, LPBYTE lpSectBuff);
 
};
 
class DiskSector
{
private:
  DiskSectorRW *util;
public:
  DiskSector();
  ~DiskSector();
  bool Open(char *vol);
  void Close();
  bool ReadSector(DWORD sector, char *Buffer, int sectorSize = 512);
  bool WriteSector(DWORD sector, char *buffer, int sectorSize = 512);
};
 
#include <stdio.h>
 
/* ----------------------------------------------------------------------------- 
 * Copyright (c) 2003 lallous <lallousx86@yahoo.com>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ----------------------------------------------------------------------------- 
 
 
 Reference
 ----------
 
  http://homepages.borland.com/efg2lab/Library/UseNet/2001/0625c.txt
  http://www.winterdom.com/dev/ptk/lock.c
  http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q168/1/80.ASP&NoWebContent=1 (locking)
  http://support.microsoft.com/default.aspx?scid=kb;EN-US;q174569 (Read/write sectors)
 
 History
 ----------
  02/17/2004  - Initial version
*/
 
 
#define VWIN32_DIOC_DOS_IOCTL     1 // specified MS-DOS device I/O ctl - Interrupt 21h Function 4400h - 4411h
#define VWIN32_DIOC_DOS_INT25     2 // Absolute Disk Read command - Interrupt 25h
#define VWIN32_DIOC_DOS_INT26     3 // Absolute Disk Write command - Interrupt 25h
#define VWIN32_DIOC_DOS_INT13     4 // Interrupt 13h commands
#define VWIN32_DIOC_SIMCTRLC      5 // Simulate Ctrl-C
#define VWIN32_DIOC_DOS_DRIVEINFO 6 // Interrupt 21h Function 730X commands
 
#define CARRY_FLAG 1
 
#ifndef INVALID_SET_FILE_POINTER
#define INVALID_SET_FILE_POINTER (DWORD)-1
#endif
 
#pragma pack(1)
typedef struct _DISKIO {
  DWORD  dwStartSector;   // starting logical sector number
  WORD   wSectors;        // number of sectors
  DWORD  dwBuffer;        // address of read/write buffer
} DISKIO, * PDISKIO;
 
typedef struct _DIOC_REGISTERS
{
  DWORD reg_EBX;
  DWORD reg_EDX;
  DWORD reg_ECX;
  DWORD reg_EAX;
  DWORD reg_EDI;
  DWORD reg_ESI;
  DWORD reg_Flags;
} DIOC_REGISTERS, *PDIOC_REGISTERS;
 
#pragma pack()
 
 
// -----------------------------------------------------------------------------------
// DiskSector WinNT
//
bool DiskSectorWinNT::Open(char *vol)
{
  char szDrive[10];
  sprintf(szDrive, "\\\\.\\%c:", vol[0]);
  m_hDisk = ::CreateFile(
    szDrive, 
    GENERIC_READ | GENERIC_WRITE, 
    FILE_SHARE_READ | FILE_SHARE_WRITE, 
    NULL, 
    OPEN_EXISTING, 
    0, 
    NULL);
  return m_hDisk != INVALID_HANDLE_VALUE;
}
 
void DiskSectorWinNT::Close()
{
  if (m_hDisk != INVALID_HANDLE_VALUE)
    ::CloseHandle(m_hDisk);
}
 
bool DiskSectorWinNT::ReadSector (DWORD sector, char *Buffer, int sectorSize)
{
  DWORD read = 0;
 
  if (::SetFilePointer(m_hDisk, sector, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
    return false;
 
  if (!::ReadFile(m_hDisk, Buffer, sectorSize, &read, NULL))
    return false;
  return true;
}
 
bool DiskSectorWinNT::WriteSector(DWORD sector, char *Buffer, int sectorSize)
{
  DWORD wrote = 0;
  
  if (::SetFilePointer(m_hDisk, sector, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
    return false;
 
  if (!::WriteFile(m_hDisk, Buffer, sectorSize, &wrote, NULL))
    return false;
 
  return true;
}
 
 
// -----------------------------------------------------------------------------------
// DiskSector
//
DiskSector::DiskSector()
{
  if (GetVersion() > 0x80000000)
    util = new DiskSectorWin9x;
  else
    util = new DiskSectorWinNT;
}
 
void DiskSector::Close()
{
  util->Close();
}
 
bool DiskSector::Open(char *vol)
{
  return util->Open(vol);
}
 
bool DiskSector::WriteSector(DWORD sector, char *Buffer, int sectorSize)
{
  return util->WriteSector(sector, Buffer, sectorSize);
}
 
bool DiskSector::ReadSector(DWORD sector, char *Buffer, int sectorSize)
{
  return util->ReadSector(sector, Buffer, sectorSize);
}
 
DiskSector::~DiskSector()
{
  delete util;
}
 
 
// -----------------------------------------------------------------------------------
// DiskSector Win9x
//
bool DiskSectorWin9x::Open(char *vol)
{
  OSVERSIONINFOEX osvi = {0};
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
 
  m_bOpened = false;
 
  if (!::GetVersionEx((OSVERSIONINFO *)&osvi))
  {
    osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    if (!::GetVersionEx ((OSVERSIONINFO *)&osvi)) 
      return false;
  }
 
  if (osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
    return false;
 
  
  m_chDrive  = toupper(vol[0]);
  m_nDriveNo = m_chDrive - 'A' + 1;
 
  char temp[10] = {0};
  sprintf(temp, "%c:\\", m_chDrive);
 
  if (::GetDriveType(temp) != DRIVE_FIXED)
    return false;
 
  m_bW9xOsr2AndAbove = (osvi.dwMajorVersion >= 4 && osvi.dwMinorVersion >= 10)
    ||
    ( 
      (osvi.dwBuildNumber == 4 && osvi.dwMinorVersion == 0) && 
      (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B')
    );
 
  m_hVmm32 = ::CreateFile(
    "\\\\.\\VWIN32",      // name
    0,                      // access mode
    0,                      // share mode
    NULL,           // security descriptor
    0,                   // ho to create
    FILE_FLAG_DELETE_ON_CLOSE, // file attributes
    NULL);          // handle to file with att to copy 
 
  m_bOpened = (m_hVmm32 != INVALID_HANDLE_VALUE);
 
  return m_bOpened;
}
 
void DiskSectorWin9x::Close()
{
  if (m_bOpened)
    ::CloseHandle(m_hVmm32);
  m_bOpened = false;
}
 
 
/*------------------------------------------------------------------
ReadLogicalSectors (hDev, bDrive, dwStartSector, wSectors, lpSectBuff)
 
Purpose:
Reads sectors from a logical drive.  Uses Int 25h.
 
Parameters:
hDev
Handle of VWIN32
 
bDrive
The MS-DOS logical drive number. 1 = A, 2 = B, 3 = C, etc.
 
dwStartSector
The first logical sector to read
 
wSectors
The number of sectors to read
 
lpSectBuff
The caller-supplied buffer that will contain the sector data
 
Return Value:
Returns TRUE if successful, or FALSE if failure.
 
Comments:
This function does not validate its parameters.
------------------------------------------------------------------*/ 
bool DiskSectorWin9x::ReadLogicalSectors (HANDLE hDev,
                         BYTE   bDrive,
                         DWORD  dwStartSector,
                         WORD   wSectors,
                         LPBYTE lpSectBuff)
{
  BOOL           fResult;
  DWORD          cb;
  DIOC_REGISTERS reg = {0};
  DISKIO         dio = {0};
 
  dio.dwStartSector = dwStartSector;
  dio.wSectors      = wSectors;
  dio.dwBuffer      = (DWORD)lpSectBuff;
 
  reg.reg_EAX = bDrive - 1;    // Int 25h drive numbers are 0-based. 
  reg.reg_EBX = (DWORD)&dio;   // Drive letter 0 = A, 1 = B  2 = C ect..
  reg.reg_ECX = 0xFFFF;        // use DISKIO struct
 
  fResult = ::DeviceIoControl(hDev, VWIN32_DIOC_DOS_INT25,
    &reg, sizeof(reg),
    &reg, sizeof(reg), &cb, 0);
 
  // Determine if the DeviceIoControl call and the read succeeded.
  fResult = fResult && !(reg.reg_Flags & CARRY_FLAG);
 
  return fResult == TRUE;
}
 
 
/*------------------------------------------------------------------
WriteLogicalSectors (hDev, bDrive, dwStartSector, wSectors, lpSectBuff)
 
Purpose:
Writes sectors to a logical drive. Uses Int 26h
 
Parameters:
hDev
Handle of VWIN32
 
bDrive
The MS-DOS logical drive number. 1 = A, 2 = B, 3 = C, etc.
 
dwStartSector
The first logical sector to write
 
wSectors
The number of sectors to write
 
lpSectBuff
The caller-supplied buffer that contains the sector data
 
Return Value:
Returns TRUE if successful, or FALSE if failure.
 
Comments:
This function does not validate its parameters.
------------------------------------------------------------------*/ 
bool DiskSectorWin9x::WriteLogicalSectors (HANDLE hDev,
                          BYTE   bDrive,
                          DWORD  dwStartSector,
                          WORD   wSectors,
                          LPBYTE lpSectBuff)
{
  BOOL           fResult;
  DWORD          cb;
  DIOC_REGISTERS reg = {0};
  DISKIO         dio = {0};
 
  dio.dwStartSector = dwStartSector;
  dio.wSectors      = wSectors;
  dio.dwBuffer      = (DWORD)lpSectBuff;
 
  reg.reg_EAX = bDrive - 1;    // Int 26h drive numbers are 0-based.
  reg.reg_EBX = (DWORD)&dio;
  reg.reg_ECX = 0xFFFF;        // use DISKIO struct
 
  fResult = ::DeviceIoControl(hDev, VWIN32_DIOC_DOS_INT26,
    &reg, sizeof(reg),
    &reg, sizeof(reg), &cb, 0);
 
  // Determine if the DeviceIoControl call and the write succeeded.
  fResult = fResult && !(reg.reg_Flags & CARRY_FLAG);
 
  return fResult == TRUE;
}
 
 
/*------------------------------------------------------------------
NewReadSectors(hDev, bDrive, dwStartSector, wSectors, lpSectBuff)
 
Purpose:
Reads the specified number of sectors into a caller-supplied
buffer. Uses Int 21h function 7305h
 
Parameters:
hDev
Handle of VWIN32
 
bDrive
The MS-DOS logical drive number. 0 = default, 1 = A, 2 = B,
3 = C, etc.
 
dwStartSector
The first sector to read.
 
wSectors
The number of sectors to read.
 
lpSectBuff
The caller-supplied buffer to read into.
 
Return Value:
Returns TRUE if successful, or FALSE if failure.
 
Comments:
This function does not validate its parameters.  It assumes that
lpSectBuff is allocated by the caller and is large enough to
hold all of the data from all of the sectors being read.
------------------------------------------------------------------*/ 
bool DiskSectorWin9x::NewReadSectors(HANDLE hDev,
                    BYTE   bDrive,
                    DWORD  dwStartSector,
                    WORD   wSectors,
                    LPBYTE lpSectBuff)
{
  BOOL           fResult;
  DWORD          cb;
  DIOC_REGISTERS reg = {0};
  DISKIO         dio;
 
  dio.dwStartSector = dwStartSector;
  dio.wSectors      = wSectors;
  dio.dwBuffer      = (DWORD)lpSectBuff;
 
  reg.reg_EAX = 0x7305;   // Ext_ABSDiskReadWrite
  reg.reg_EBX = (DWORD)&dio;
  reg.reg_ECX = -1;
  reg.reg_EDX = bDrive;   // Int 21h, fn 7305h drive numbers are 1-based
 
  fResult = ::DeviceIoControl(hDev, VWIN32_DIOC_DOS_DRIVEINFO,
    &reg, sizeof(reg),
    &reg, sizeof(reg), &cb, 0);
 
  // Determine if the DeviceIoControl call and the read succeeded.
  fResult = fResult && !(reg.reg_Flags & CARRY_FLAG);
 
  return fResult == TRUE;
}
 
 
/*------------------------------------------------------------------
NewWriteSectors(hDev, bDrive, dwStartSector, wSectors, lpSectBuff)
 
Purpose:
Writes the specified number of sectors from a caller-supplied
buffer. Uses Int 21h function 7305h
 
Parameters:
hDev
Handle of VWIN32
 
bDrive
The MS-DOS logical drive number. 0 = default, 1 = A, 2 = B,
3 = C, etc.
 
dwStartSector
The first sector to write.
 
wSectors
The number of sectors to write.
 
lpSectBuff
The caller-supplied buffer from which to write.
 
Return Value:
Returns TRUE if successful, or FALSE if failure.
 
Comments:
This function does not validate its parameters.  It assumes that
lpSectBuff is allocated by the caller and is large enough to
hold all of the data to be written.
------------------------------------------------------------------*/ 
bool DiskSectorWin9x::NewWriteSectors(HANDLE hDev,
                     BYTE   bDrive,
                     DWORD  dwStartSector,
                     WORD   wSectors,
                     LPBYTE lpSectBuff)
{
  BOOL           fResult;
  DWORD          cb;
  DIOC_REGISTERS reg = {0};
  DISKIO         dio;
 
  dio.dwStartSector = dwStartSector;
  dio.wSectors      = wSectors;
  dio.dwBuffer      = (DWORD)lpSectBuff;
 
  reg.reg_EAX = 0x7305;   // Ext_ABSDiskReadWrite
  reg.reg_EBX = (DWORD)&dio;
  reg.reg_ECX = -1;
  reg.reg_EDX = bDrive;   // Int 21h, fn 7305h drive numbers are 1-based
 
  reg.reg_ESI = 0x6001;   // Normal file data/write (See function
  // documentation for other values)
 
 
  fResult = ::DeviceIoControl(hDev, VWIN32_DIOC_DOS_DRIVEINFO,
    &reg, sizeof(reg),
    &reg, sizeof(reg), &cb, 0);
 
  // Determine if the DeviceIoControl call and the write succeeded.
  fResult = fResult && !(reg.reg_Flags & CARRY_FLAG);
 
  return fResult == TRUE;
}
 
/*-----------------------------------------------------------------------
LockLogicalVolume (hVWin32, bDriveNum, bLockLevel, wPermissions)
 
Purpose:
Takes a logical volume lock on a logical volume.
 
Parameters:
hVWin32
An open handle to VWIN32.
 
bDriveNum
The logical drive number to lock. 0 = default, 1 = A:, 2 = B:,
3 = C:, etc.
 
bLockLevel
Can be 0, 1, 2, or 3. Level 0 is an exclusive lock that can only
be taken when there are no open files on the specified drive.
Levels 1 through 3 form a hierarchy where 1 must be taken before
2, which must be taken before 3.
 
wPermissions
Specifies how the lock will affect file operations when lock levels
1 through 3 are taken. Also specifies whether a formatting lock
should be taken after a level 0 lock.
 
Zero is a valid permission.
 
Return Value:
If successful, returns TRUE.  If unsuccessful, returns FALSE.
-----------------------------------------------------------------------*/ 
bool DiskSectorWin9x::LockLogicalVolume (HANDLE hVWin32,
                               BYTE   bDriveNum,
                               BYTE   bLockLevel,
                               WORD   wPermissions)
{
  BOOL           fResult;
  DIOC_REGISTERS regs = {0};
  BYTE           bDeviceCat;  // can be either 0x48 or 0x08
  DWORD          cb;
 
  /*
  Try first with device category 0x48 for FAT32 volumes. If it
  doesn't work, try again with device category 0x08. If that
  doesn't work, then the lock failed.
  */ 
 
  bDeviceCat = 0x48;
 
ATTEMPT_AGAIN:
  // Set up the parameters for the call.
  regs.reg_EAX = 0x440D;
  regs.reg_EBX = MAKEWORD(bDriveNum, bLockLevel);
  regs.reg_ECX = MAKEWORD(0x4A, bDeviceCat);
  regs.reg_EDX = wPermissions;
 
  fResult = ::DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
    &regs, sizeof(regs), &regs, sizeof(regs),
    &cb, 0);
 
  // See if DeviceIoControl and the lock succeeded
  fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
 
  // If DeviceIoControl or the lock failed, and device category 0x08
  // hasn't been tried, retry the operation with device category 0x08.
  if (!fResult && (bDeviceCat != 0x08))
  {
    bDeviceCat = 0x08;
    goto ATTEMPT_AGAIN;
  }
 
  return fResult == TRUE;
}
 
/*-----------------------------------------------------------------------
UnlockLogicalVolume (hVWin32, bDriveNum)
 
Purpose:
Unlocks a logical volume that was locked with LockLogicalVolume().
 
Parameters:
hVWin32
An open handle to VWIN32.
 
bDriveNum
The logical drive number to unlock. 0 = default, 1 = A:, 2 = B:,
3 = C:, etc.
 
Return Value:
If successful, returns TRUE. If unsuccessful, returns FALSE.
 
Comments:
Must be called the same number of times as LockLogicalVolume() to
completely unlock a volume.
 
Only the lock owner can unlock a volume.
-----------------------------------------------------------------------*/ 
bool DiskSectorWin9x::UnlockLogicalVolume (HANDLE hVWin32, BYTE bDriveNum)
{
  BOOL           fResult;
  DIOC_REGISTERS regs = {0};
  BYTE           bDeviceCat;  // can be either 0x48 or 0x08
  DWORD          cb;
 
  /* Try first with device category 0x48 for FAT32 volumes. If it
  doesn't work, try again with device category 0x08. If that
  doesn't work, then the unlock failed.
  */ 
 
  bDeviceCat = 0x48;
 
ATTEMPT_AGAIN:
  // Set up the parameters for the call.
  regs.reg_EAX = 0x440D;
  regs.reg_EBX = bDriveNum;
  regs.reg_ECX = MAKEWORD(0x6A, bDeviceCat);
 
  fResult = ::DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
    &regs, sizeof(regs), &regs, sizeof(regs),
    &cb, 0);
 
  // See if DeviceIoControl and the unlock succeeded
  fResult = fResult && !(regs.reg_Flags & CARRY_FLAG);
 
  // If DeviceIoControl or the unlock failed, and device category 0x08
  // hasn't been tried, retry the operation with device category 0x08.
  if (!fResult && (bDeviceCat != 0x08))
  {
    bDeviceCat = 0x08;
    goto ATTEMPT_AGAIN;
  }
  return fResult == TRUE;
}
 
 
bool DiskSectorWin9x::ReadSector (DWORD sector, char *Buffer, int sectorSize)
{
  if (!m_bOpened)
    return false;
 
  if (m_bUseLocking)
  {
    if (!LockLogicalVolume(m_hVmm32, m_nDriveNo, 1, 1))
      return false;
 
    if (!LockLogicalVolume(m_hVmm32, m_nDriveNo, 2, 0))
    {
      UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
      return false;
    }
  }
 
  bool bRet;
  if (m_bW9xOsr2AndAbove)
    bRet = NewReadSectors(m_hVmm32, m_nDriveNo, sector, 1, (LPBYTE)Buffer);
  else
    bRet = ReadLogicalSectors(m_hVmm32, m_nDriveNo, sector, 1, (LPBYTE)Buffer);
 
  if (m_bUseLocking)
  {
    UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
    UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
  }
  return bRet;
}
 
bool DiskSectorWin9x::WriteSector (DWORD sector, char *Buffer, int sectorSize)
{
  if (!m_bOpened)
    return false;
 
  if (!LockLogicalVolume(m_hVmm32, m_nDriveNo, 1, 1))
    return false;
 
  if (!LockLogicalVolume(m_hVmm32, m_nDriveNo, 2, 0))
  {
    UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
    return false;
  }
 
  if (!LockLogicalVolume(m_hVmm32, m_nDriveNo, 3, 0))
  {
    UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
    UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
    return false;
  }
 
  bool bRet;
 
  if (m_bW9xOsr2AndAbove)
    bRet = NewWriteSectors(m_hVmm32, m_nDriveNo, sector, 1, (LPBYTE) Buffer);
  else
    bRet = WriteLogicalSectors(m_hVmm32, m_nDriveNo, sector, 1, (LPBYTE) Buffer);
 
  UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
  UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
  UnlockLogicalVolume(m_hVmm32, m_nDriveNo);
 
  return bRet;
}
 
void ShowErrorString(char* p)
{
  printf("%s\n",p);
}
 
void SetSerial()
{
  DiskSector disk;
 
  const DWORD newSerial = 123456789;
 
  const int max_pbsi = 3;
 
  struct partial_boot_sector_info
  {
    LPSTR Fs; // file system name
    DWORD FsOffs; // offset of file system name in the boot sector
    DWORD SerialOffs; // offset of the serialnumber in the boot sector
  };
 
  partial_boot_sector_info pbsi[max_pbsi] =
  {
   {"FAT32", 0x52, 0x43},
   {"FAT",   0x36, 0x27},
   {"NTFS",  0x03, 0x48}
  };
 
  TCHAR szDrive[12];
 
  char Sector[512];
 
  DWORD i;
 
  sprintf(szDrive, "%c:\\", 'c');
 
  if (!disk.Open(szDrive))
  {
    ShowErrorString("Could not open disk!");
    return;
  }
 
  // read sector
  if (!disk.ReadSector(0, Sector))
  {
    ShowErrorString("Could not read sector!");
    return;
  }
 
  // try to search for a valid boot sector
  for (i=0;i<max_pbsi;i++)
  {
    if (strncmp(pbsi[i].Fs, Sector+pbsi[i].FsOffs, strlen(pbsi[i].Fs)) == 0)
    {
      // we found a valid signature
      break;
    }
  }
 
  if (i >= max_pbsi)
  {
    MessageBoxA(NULL,"Cannot change serial number of this file system!", "Error", MB_ICONERROR);
    return;
  }
  
  // patch serial number
  *(PDWORD)(Sector+pbsi[i].SerialOffs) = newSerial;
 
  // write boot sector
  if (!disk.WriteSector(0, Sector))
  {
    ShowErrorString("Could not write sector!");
    return;
  }
 
  ShowErrorString("Volume serial number changed successfully!\r"
                  "You might want to restart your system for changes to take effect!");
}
 
void main()
{
  SetSerial();
  ExitWindowsEx(EWX_REBOOT,0);
}

Open in new window

Avatar of KingSencat
KingSencat

ASKER

let me check it, thanks so far
I did exactly what you say .. and i run this file in 3 different computers. The serial change but are not all the same serial numbers. I will appriciated if you can make this program to set the following Serial : 075B-CD15

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks for your great help, finally i get it work :) . Do you know if this is compatible with Windows VIsta?

Thanks :)
Good, question - it should be.
I just tryed with vista and it's doesnt work :( . Any solution for this ? i can open another 1 question if you know how to do it compatible with vista. thanks jkr
What error do you get? You need to be logged on as Administrator.
Actually i dont get any error.. after i run the .exe i restart my pc and the serial remain the same. Also i have tryed to do it manual using the original.exe but it doesnt let me . After i push button "Change serial number" its apear one windows message "Could not open disk!"
Ahhh, I see - seems that there is no VWIN32 on Vista, will check that later.
Thanks jkr, i am waiting for your response :D
Sorry, I almost forgot - bad news, there indeed is no VWIN32 object on Vista...
Any way to change the serial number  automatic when ur using windows vista?
Don't know, will check...
any updates on this jkr?
Ooops, sorry, I thought I already *had* updated this question, but apparently something went wrong (and I would not rule out that it was my fault, i.e. writing and then closing teh browser window)...

Unfortunatly, it is only bad news, no"VXD32" on Vista.