From: Bu on
Hello,
Can somebody tell me what VB6 code i need to get the size of a disk?

Thanks in advance
Bu
From: Mike Williams on
"Bu" <si(a)si.si> wrote in message
news:a63tf5tiqupm6vo5amut3u4erdju6ai2gc(a)4ax.com...

> Hello, Can somebody tell me what VB6 code
> i need to get the size of a disk?

Have a look at the following (make sure you read some of the important
notes):

http://msdn.microsoft.com/en-us/library/aa364937(VS.85).aspx

Here's how you can use it in VB6:

Mike

Option Explicit
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long

Private Sub Command1_Click()
Me.AutoRedraw = True
Dim totalBytes As Currency
Dim BytesFreeToCaller As Currency, BytesFree As Currency
GetDiskFreeSpaceEx "c:\", BytesFreeToCaller, totalBytes, BytesFree
totalBytes = totalBytes * 10000&
BytesFreeToCaller = BytesFreeToCaller * 10000&
BytesFree = BytesFree * 10000&
Print "Bytes free to caller: "; BytesFreeToCaller
End Sub




From: Larry Serflaten on

"Bu" <si(a)si.si> wrote
> Hello,
> Can somebody tell me what VB6 code i need to get the size of a disk?

If its for your own use, you could use WMI:

Private Sub Command1_Click()
Set WMI = GetObject("winmgmts:")
For Each DSK In WMI.ExecQuery("Select DeviceID, Size, FreeSpace from Win32_LogicalDisk", , 48)
Debug.Print DSK.DeviceID, DSK.Size, DSK.FreeSpace
Next
End Sub


LFS


From: Bu on
On Sat, 14 Nov 2009 07:52:08 -0500, "Larry Serflaten"
<serflaten(a)usinternet.com> wrote:

>
>"Bu" <si(a)si.si> wrote
>> Hello,
>> Can somebody tell me what VB6 code i need to get the size of a disk?
>
>If its for your own use, you could use WMI:
>
>Private Sub Command1_Click()
> Set WMI = GetObject("winmgmts:")
> For Each DSK In WMI.ExecQuery("Select DeviceID, Size, FreeSpace from Win32_LogicalDisk", , 48)
> Debug.Print DSK.DeviceID, DSK.Size, DSK.FreeSpace
> Next
>End Sub
>
>
>LFS
>
Larry and Mike thanks for the fast response.
I go for Larry's solution. Just wondering why you can ue it only in
your own code.
Bu

From: mayayana on
WMI is a tool for system info. and sys. admin.
management introduced with either Win2000 or
WinME. (I'm not sure which.) It's not Windows
API. Earlier systems will not have it unless it's
been specifically installed.

On NT systems WMI runs as a service. If the
WMI Process Launcher service has been shut off
then WMI is not available. (I'm not sure whether
there might be another service dependency.)

Since WMI is mainly used by system administrators
via scripting, others could have it shut down for
security or performance reasons.

So while there's a good chance that you'll be able
to use WMI on any system where you ship your
software, it's not certain, and taking that risk is
unnecessary when you can easily use the Windows
API instead.

On top of that, WMI is slow, bloated, and really
provides little of interest other than system info.
It has Windows Installer functions that are just an
inferior wrapper around existing WI APIs. It has
Registry functions that are poorly designed and
superfluous if you have the Registry API. Etc.


> I go for Larry's solution. Just wondering why you can ue it only in
> your own code.
> Bu
>