Please tell me the easiest way to get the serial number of the hard disk (factory), or give the source code on c ++ or assembler.

So here I wrote, gives an error

link to unresolved external _WinMain @ 16 symbol in the ___tmainCRTStartup function

My code does not feel right, so please help, correct errors, and explain what's what.

#include <iostream> #include <windows.h> #include <winioctl.h> #include <tchar.h> using namespace std; _OVERLAPPED ol; _STORAGE_PROPERTY_QUERY spg; LPVOID lpInBuffer[1024]; LPVOID lpOutBuffer[1024]; LPDWORD lpByteReturned; int main() { HANDLE hDevice = CreateFile(_T("\\.\DeviceName"), NULL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); BOOL bResult = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &spg, sizeof(spg), &spg, sizeof(spg), lpByteReturned, &ol); if(bResult) cout << "Error by DeviceIoControl!!!\n"; else { cout << spg.PropertyId << "\n"; cout << spg.QueryType << "\n"; cout << spg.AdditionalParameters[0] << "\n"; } system("PAUSE"); return 0; } 
  • You have incorrectly configured the development environment. To start, do not "empty project", which implies the absence of any generated source files at all, but the "win32 project", but everywhere you put the checkboxes, that you need a console project, you can use MFC. Then the main _tmain() program will be called .... _tmain() . And it is with underscores. So write in it everything you need. EC, but I assume that you have MSVC ++. - gecube

2 answers 2

Since you haven't prudently specified an OS, I’ll think about it for you and tell you how it is done under Windows.

Take a DeviceIoControl and request IOCTL_STORAGE_QUERY_PROPERTY from it. The source is here: diskid32.cpp

    1. Direct access to equipment. Make available I / O ports (for example, using the userport or giveo driver, you can write the driver yourself). Then work with the ports of the hard disk controller. Hope this stuff helps. You need to send the command 0xEC (IDENTIFY DEVICE) and get a passport from the island. Find a serial in it is not a problem.
    2. IOCTL_SCSI_PASS_THROUGH_DIRECT and similar - you can send commands directly to the Windows directly from Windows. Do not look at SCSI in the IOCTL name. This IOCTL also works for most IDE controller drivers. But it may take a little podshamanit.
    3. Work through IOCTL_STORAGE_QUERY_PROPERTY