Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / April 2008



Tip: Looking for answers? Try searching our database.

List Physical Drives (c++ | WINAPI)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CAHEK - 02 Apr 2008 08:54 GMT
Hello!
I want to list all physical drives on my machine...
anybody knows how to do this?

(win32 api, c++)
mike - 02 Apr 2008 09:09 GMT
> Hello!
> I want to list all physical drives on my machine...
> anybody knows how to do this?
>
> (win32 api, c++)

You can use this in a loop to scan for drives

Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Long

I didn't write this, but don't remember where I stole it...
checks to see if there's any media in removable drives.

Private Function DeviceCheckMedia(sDrive As String) As Long

   Dim hDevice As Long
   Dim bytesReturned As Long
   Dim success As Long

  'the drive letter has to be passed
  'without a trailing slash (ie 'G:')

   hDevice = CreateFile("\\.\" & sDrive, _
                        GENERIC_READ, _
                        FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                        ByVal 0&, _
                        OPEN_EXISTING, _
                        0&, 0&)

   If hDevice <> INVALID_HANDLE_VALUE Then

     'If the operation succeeds and
     'the device media are accessible,
     'DeviceIoControl returns a nonzero value
      success = DeviceIoControl(hDevice, _
                                IOCTL_STORAGE_CHECK_VERIFY, _
                                0&, _
                                0&, _
                                ByVal 0&, _
                                0&, _
                                bytesReturned, _
                                ByVal 0&)

   End If

   Call CloseHandle(hDevice)
   DeviceCheckMedia = success <> 0

End Function

Signature

Return address is VALID!

CAHEK - 02 Apr 2008 09:13 GMT
ok thanks i think i understand
i'll try this
Larry Serflaten - 02 Apr 2008 13:06 GMT
> Hello!
> I want to list all physical drives on my machine...
> anybody knows how to do this?

WMI method:

Private Sub Form_Load()
' Adatped from MSDN Scriptomatic Ver 2
On Error Resume Next

Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20

  Set objWMIService = GetObject("winmgmts:")
  Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
                                         wbemFlagReturnImmediately + wbemFlagForwardOnly)

  For Each objItem In colItems
     Debug.Print "Model: " & objItem.Model
     Debug.Print "Name: " & objItem.Name
     Debug.Print "Partitions: " & objItem.Partitions
     Debug.Print "Size: " & objItem.Size & vbCrLf
  Next

End Sub
Thorsten Albers - 02 Apr 2008 15:49 GMT
CAHEK <h4cker_rus@hotmail.com> schrieb im Beitrag
<47f33c6f$0$853$ba4acef3@news.orange.fr>...
> Hello!
> I want to list all physical drives on my machine...
> anybody knows how to do this?
> (win32 api, c++)

This newsgroup is for MS Visual Basic and not for 'c++'. That's why it has
".vb." in its name. You should ask your question in an appropriate
newsgroup in order to get answers useful for you.

Signature

----------------------------------------------------------------------
THORSTEN ALBERS                       Universität Freiburg
                                               albers@
                                                      uni-freiburg.de
----------------------------------------------------------------------

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.