Click here to Skip to main content
15,886,806 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGetDiskDrive Pin
p_196027-May-09 22:38
p_196027-May-09 22:38 
AnswerRe: GetDiskDrive Pin
Hamid_RT27-May-09 23:17
Hamid_RT27-May-09 23:17 
GeneralRe: GetDiskDrive Pin
p_196027-May-09 23:27
p_196027-May-09 23:27 
AnswerRe: GetDiskDrive Pin
Jacobb Michael28-May-09 0:06
Jacobb Michael28-May-09 0:06 
AnswerRe: GetDiskDrive Pin
Naveen28-May-09 1:56
Naveen28-May-09 1:56 
GeneralRe: GetDiskDrive Pin
p_196028-May-09 2:51
p_196028-May-09 2:51 
GeneralRe: GetDiskDrive Pin
Naveen28-May-09 3:13
Naveen28-May-09 3:13 
QuestionZwOpenFile and hard disks Pin
andrew_dk27-May-09 21:56
andrew_dk27-May-09 21:56 
I had code to access the serial number of a hard drive. I was running this in user mode, getting a handle to the drive as follows:

HANDLE hDrive ;
wchar_t driveName[128];

for(int i = 0; i < 16; ++i)
{
  wsprintf(driveName, L"\\\\.\\PhysicalDrive%d", drive);
  hDrive = CreateFile(driveName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE , NULL, OPEN_EXISTING, 0, NULL);
  ...
}


I'm now trying to do the same thing in a driver. However I'm not sure how to open the actual drive. Currently the code I have is:
HANDLE hDrive;
WCHAR sDriveName[128];
OBJECT_ATTRIBUTES oa;
UNICODE_STRING usDriveName;
IO_STATUS_BLOCK iosb;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
int drive;

for(drive = 0; drive < MAX_IDE_DRIVES; drive++)
{	
  _snwprintf(sDriveName, 128, L"\\Device\\Harddisk%lu", drive);
  RtlInitUnicodeString(&usDriveName, sDriveName);

  InitializeObjectAttributes(&oa, &usDriveName, OBJ_INHERIT, NULL, NULL);

 if(NT_SUCCESS(ZwOpenFile(&hDrive, FILE_ALL_ACCESS, &oa, &iosb, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_DIRECTORY_FILE)))
  {
    ...
  }
}


However the call to ZwOpenFile is failing with iosb.Status == 3.

Any ideas what I am doing wrong here??
Thanks.
QuestionRe: ZwOpenFile and hard disks Pin
David Crow28-May-09 4:24
David Crow28-May-09 4:24 
AnswerRe: ZwOpenFile and hard disks Pin
andrew_dk28-May-09 11:06
andrew_dk28-May-09 11:06 
QuestionCHANGE THE POSITION OF CONTROL OR BUTTON Pin
johnjitu27-May-09 21:54
johnjitu27-May-09 21:54 
AnswerRe: CHANGE THE POSITION OF CONTROL OR BUTTON Pin
Chandrasekharan P27-May-09 22:09
Chandrasekharan P27-May-09 22:09 
QuestionRe: CHANGE THE POSITION OF CONTROL OR BUTTON Pin
CPallini27-May-09 22:17
mveCPallini27-May-09 22:17 
QuestionRe: CHANGE THE POSITION OF CONTROL OR BUTTON Pin
«_Superman_»27-May-09 22:21
professional«_Superman_»27-May-09 22:21 
QuestionHow to get the Friendly name of the removable drive by the Drive letter ? Pin
Jacobb Michael27-May-09 20:45
Jacobb Michael27-May-09 20:45 
AnswerRe: How to get the Friendly name of the removable drive by the Drive letter ? Pin
Stuart Dootson27-May-09 22:24
professionalStuart Dootson27-May-09 22:24 
GeneralRe: How to get the Friendly name of the removable drive by the Drive letter ? Pin
Jacobb Michael27-May-09 23:52
Jacobb Michael27-May-09 23:52 
GeneralRe: How to get the Friendly name of the removable drive by the Drive letter ? Pin
Stuart Dootson28-May-09 1:03
professionalStuart Dootson28-May-09 1:03 
GeneralRe: How to get the Friendly name of the removable drive by the Drive letter ? Pin
Jacobb Michael28-May-09 2:30
Jacobb Michael28-May-09 2:30 
GeneralRe: How to get the Friendly name of the removable drive by the Drive letter ? Pin
Stuart Dootson28-May-09 2:32
professionalStuart Dootson28-May-09 2:32 
Questionhow can i find file in subFolder? Pin
002comp27-May-09 20:34
002comp27-May-09 20:34 
AnswerRe: how can i find file in subFolder? Pin
Nuri Ismail27-May-09 20:59
Nuri Ismail27-May-09 20:59 
AnswerRe: how can i find file in subFolder? Pin
«_Superman_»27-May-09 22:16
professional«_Superman_»27-May-09 22:16 
GeneralRe: how can i find file in subFolder? Pin
002comp27-May-09 23:24
002comp27-May-09 23:24 
AnswerRe: how can i find file in subFolder? Pin
Hamid_RT27-May-09 23:25
Hamid_RT27-May-09 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.