Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Drive handle via CreateFile


  • Please log in to reply
2 replies to this topic

#1 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 10:01 PM

Trying to get the handle to drive 0 and this isn't working; why? thanks...
(this one returns 0) $hDrv = _WinAPI_CreateFileEx( "\\.\PhysicalDrive0", 0, 3, 0, 3, 0, 0) ; Returns 0 (this one returns null) $hDrv = DllCall('kernel32.dll', 'ptr', 'CreateFile', 'str', "\\.\PhysicalDrive0", 'dword', 0, 'dword', 3, 'ptr', 0, 'dword', 3, 'dword', 0, 'ptr', 0) ; Returns null (from WinAPIEx.au3) Func _WinAPI_CreateFileEx($sFile, $iCreation, $iAccess = 0, $iShare = 0, $iFlagsAndAttributes = 0, $tSecurity = 0, $hTemplate = 0) Local $Ret = DllCall('kernel32.dll', 'ptr', 'CreateFileW', 'wstr', $sFile, 'dword', $iAccess, 'dword', $iShare, 'ptr', DllStructGetPtr($tSecurity), 'dword', $iCreation, 'dword', $iFlagsAndAttributes, 'ptr', $hTemplate) If (@error) Or ($Ret[0] = Ptr(-1)) Then   Return SetError(1, 0, 0) EndIf Return $Ret[0] EndFunc   ;==>_WinAPI_CreateFileEx








#2 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 20 February 2012 - 07:45 AM

_WinAPI_CreateFileEx('.PhysicalDrive0', $OPEN_EXISTING, 0, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE))

or
_WinAPI_CreateFileEx('.PhysicalDrive0', 3, 0, 3)

Edited by Yashied, 20 February 2012 - 07:46 AM.


#3 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,397 posts

Posted 20 February 2012 - 09:53 AM

On Vista+ Admin rights might be necessary.

MSDN: CreateFile function

"dwDesiredAccess [in]
If this parameter is zero, the application can query certain metadata such as file, directory, or device attributes without accessing that file or device, even if GENERIC_READ access would have been denied."

"Physical Disks and Volumes
Direct access to the disk or to a volume is restricted. For more information, see "Changes to the file system and to the storage stack to restrict direct disk access and direct volume access in Windows Vista and in Windows Server 2008" in the Help and Support Knowledge Base at http://support.microsoft.com/kb/942448."

So querying device attributes with dwDesiredAccess = 0 will work without admin rights, whereas access to the content will require admin rights.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users