LPCTSTR str = wth;//\\.\PHYSICALDRIVE1
HANDLE hDevice=CreateFile(str,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
if(hDevice==INVALID_HANDLE_VALUE)
{
printf("read disk error!\n");
}
DISK_GEOMETRY DiskGeom1;DWORD return_bytes;
if(!DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY,NULL,0,&DiskGeom1,sizeof(DISK_GEOMETRY),&return_bytes,NULL))
{
printf("DeviceIoControl error!\n");
//int ret = GetLastError();
CloseHandle(hDevice);
CloseHandle(hDevice);
}
unsigned long writed = 0;
for(int i=0;i<1024;i++)
{
int ret =0;
ret= WriteFile(hDevice,ch,1024*1024,&writed,NULL);
if(ret>0)
{
printf("write disk now!\n");
printf("ret=%d\n",ret);
}
else
printf("write disk error!\n");
}
FlushFileBuffers(hDevice);
CloseHandle(hDevice);