|
-
Dec 31st, 2005, 02:22 AM
#1
Thread Starter
Frenzied Member
Weird System Info!
I am using the following code to get the system information of the user's machine. A ImageCombo lists all the hard drives. Since I want only the hard drives, I am using the ImageCombo & not a DriveListBox (NOTE: This isn't my code):
VB Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias..........
Private Declare Function GetVersionEx Lib "kernel32.dll" Alias..........
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias..........
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias..........
Private Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Dim OsInfo As OSVERSIONINFO
Dim tmp As String
Dim FreeUser As ULARGE_INTEGER
Dim Total As ULARGE_INTEGER
Dim FreeSys As ULARGE_INTEGER
Dim Temp As Currency
Dim fTemp As Currency
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias.....
Private Declare Function GetDriveType Lib "kernel32" Alias.....
Private Function [b]GetDriveTypeFromLetter(strDriveLetter As String) As String[/b]
Dim strDrive As String
If Right(strDriveLetter, 1) <> "\" Then
strDrive = strDriveLetter & "\"
Else
strDrive = strDriveLetter
End If
Select Case GetDriveType(strDrive)
Case 2
GetDriveTypeFromLetter = "Removable"
Case 3
GetDriveTypeFromLetter = "Fixed Hard Drive"
Case Is = 4
GetDriveTypeFromLetter = "Remote"
Case Is = 5
GetDriveTypeFromLetter = "CD-ROM"
Case Is = 6
GetDriveTypeFromLetter = "Ram disk"
Case Else
GetDriveTypeFromLetter = "Unrecognized"
End Select
End Function
Private Sub [b]Form_Load()[/b]
Dim strSave As String, i As Long, ret&
Me.AutoRedraw = True
strSave = String(255, Chr$(0))
ret& = GetLogicalDriveStrings(255, strSave)
For i = 1 To 100
If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
If GetDriveTypeFromLetter(Left$(strSave, InStr(1, strSave, Chr$(0)) - 1)) = "Fixed Hard Drive" Then
imgCboDrives.ComboItems.Add , , Left$(strSave, InStr(1, strSave, Chr$(0)) - 1), 1
End If
strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
Next i
Call GetDrive("C:\")
imgCboDrives.ComboItems(1).Selected = True
End Sub
Function [b]GetDrive(DriveName)[/b]
On Error Resume Next
Dim retVal
lblSysInfo.Height = 985
OsInfo.dwOSVersionInfoSize = Len(OsInfo)
retVal = GetVersionEx(OsInfo)
Select Case OsInfo.dwPlatformId
Case 0
tmp = "Windows 3.x"
Case 1
tmp = "Windows 95/98"
Case 2
tmp = "Windows 2000"
End Select
lblSysInfo.Caption = "Drive: " & Left(DriveName, 2) & vbNewLine
lblSysInfo.Caption = lblSysInfo.Caption & "Version: " & OsInfo.dwMajorVersion & "." & OsInfo.dwMinorVersion & vbNewLine
lblSysInfo.Caption = lblSysInfo.Caption & "Platform: " & tmp & vbNewLine
GetDiskFreeSpaceEx Left(DriveName, 2), FreeUser, Total, FreeSys
CopyMemory Temp, Total, 8
CopyMemory fTemp, FreeUser, 8
lblSysInfo.Caption = lblSysInfo.Caption & "Total Space: " & Format$(CCur(Temp) * 10000, "#######,##") & " bytes" & vbNewLine
lblSysInfo.Caption = lblSysInfo.Caption & "Free Space: " & Format$(CCur(fTemp) * 10000, "#######,##") & " bytes" & vbNewLine
lblSysInfo.Caption = lblSysInfo.Caption & "Used Space: " & Format$(CCur(Temp) - CCur(fTemp) * 10000, "#######,##") & " bytes" & vbNewLine
End Function
Private Sub [b]imgCboDrives_Click()[/b]
Call GetDrive(imgCboDrives.Text)
End Sub
The above correctly computes the total space & the free space of the drives. Now it's pretty obvious that since I have the total space & the free space, the used space will be (Total Space - Free Space) but strangely, that gives the wrong result & that too a negative value! For e.g. in my machine, the total space of C:\ computed comes to 10,000,343,040 bytes & the free space comes to 934,223,872 bytes; so the used space should be 9,066,119,168 bytes but VB computes it to -933,223,838 bytes! I have checked the other drives as well - the outcome is always a wrong negative value.
Why this huge discrepancy & wrong result in the used space?
Last edited by arpan_de; Jan 2nd, 2006 at 01:27 PM.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
-
Dec 31st, 2005, 12:29 PM
#2
Frenzied Member
Re: Weird System Info!
Off topic, but do you have to have an explanation point at the end of *Every* thread title?
-
Dec 31st, 2005, 12:51 PM
#3
Lively Member
Re: Weird System Info!
I think it's got something to do with this piece of code:
VB Code:
Dim FreeUser As ULARGE_INTEGER
Dim Total As ULARGE_INTEGER
Dim FreeSys As ULARGE_INTEGER
I've never seen this type of variable... Are you sure vb6 can handle it properly? Maybe you should try if it works when you change it into this:
VB Code:
Dim FreeUser As Double
Dim Total As Double
Dim FreeSys As Double
I don't know if it works, but you should give it a try...
-
Jan 1st, 2006, 01:24 AM
#4
Thread Starter
Frenzied Member
Re: Weird System Info!
Off topic, but do you have to have an explanation point at the end of *Every* thread title?
"Explanation point" or "exclamation mark"??? The latter I suppose. Why, any problem with that?
Dim FreeUser As Double
Dim Total As Double
Dim FreeSys As Double
I tried your suggestion gtheman but it generates the ByRef argument type mismatch error pointing to
VB Code:
GetDiskFreeSpaceEx Left(DriveName, 2), FreeUser, Total, FreeSys
Any other ideas?
Last edited by arpan_de; Jan 2nd, 2006 at 01:28 PM.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
-
Jan 1st, 2006, 03:52 AM
#5
Re: Weird System Info!
arpan,
I would suggest that instead of using ULARGE_INTEGER you use Currency.
VB Code:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" ( _
ByVal lpDirectoryName As String, _
lpFreeBytesAvailable As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency _
) As Long
Then you can get used space by simple subtraction
VB Code:
Dim FreeUser As Currency, Total As Currency, FreeSys As Currency
Dim UsedBytes As Currency
GetDiskFreeSpaceEx Left(DriveName, 2), FreeUser, Total, FreeSys
UsedBytes = Total - FreeUser
I also have a request. Don't truncate your code lines by ...
I may want to try out your code, but you force me to enter the code myself when you do this.
-
Jan 1st, 2006, 03:54 AM
#6
Lively Member
Re: Weird System Info!
I just checked your code and I found this in the declarations :
VB Code:
Private Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
This means that every ULARGE_INTEGER (for example FreeUser), has a LowPart and a HighPart property (so in the case of FreeUser it would be FreeUser.LowPart and FreeUser.HighPart). Try messing with these values, maybe you should first substract the HighPart values, than the LowPart values, and then average them, but I don't know for sure and I can't try the code.
-
Jan 1st, 2006, 10:34 AM
#7
Thread Starter
Frenzied Member
Re: Weird System Info!
I also have a request. Don't truncate your code lines by ...
I may want to try out your code, but you force me to enter the code myself when you do this.
Yeah.....I agree.....you are very much correct........I shouldn't be truncating the code lines.........will keep in mind henceforth.
I will try out your suggestions & get back to you.
Last edited by arpan_de; Jan 2nd, 2006 at 01:28 PM.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|