المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Access to Locigal Drives under Vista



C++ Programming
08-18-2009, 04:22 AM
A piece of code that worked a dream under XP, but breaks under Vista. The Licence checking software for my code needs to find the serial number of the physical drive from which the application is launched. I Do this in the Following Steps:-

Step1: Use 'GetModuleFileName' to retrieve the app path, and hence the ligical drive. (Typically 'C:'), and running from Network Drives is Not Allowed under the license terms.

Step2: Get a Handle to the logical drive (say Chttp://www.barakasoft.com/script/Forums/Images/smiley_smile.gif using:
CreateFile("\\\\.\\\\C:",....);

Step3: Use:
DeviceIoControl(h,IOCTL_STORAGE_GET_DEVICE_NUMBER,...)
to retrieve the Physical Drive Number.

Step4: Get a Handle to the Physical Device, using CreateFile

Step5: Use:
DeviceIoControl (hPhys, IOCTL_STORAGE_QUERY_PROPERTY,..)
To retrieve a Datablock from which the serial number can be retrieved.

As said, everything works fine under XP, but it breaks at Step2 with Vista. CreateFile returns -1, even if I reduce the Security of the volume to 'Full Control by All Users'!

Step4+5 etc work fine, and appear not to be affected by the security considerations. I guess that the trick lies in submitting an appropriate security descriptor. Anyone Any Idea How??

Regards,
http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

Bram van Kampen