Hi!
I downloaded some software that checks hard disk usage for all the pc's on our network. My question is how?? Is there some sort of dos command or api call or something? I want to create a Visual Basic ap to do the same thing so I can tailor it to give warnings when some disks reach certain levels.
Any info regarding this would be most helpful!
Thanks
Andy
8 2557
Yes i created a small app to do this for my network drives, although i did it in vb 2005.
it used the follwing api -
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Long, ByRef lpTotalNumberOfBytes As Long, ByRef lpTotalNumberOfFreeBytes As Long) As Long
-
if you want my full vb2005 code then post back and i'll add it here.
James
oh nice one,
yea i dunno if you want to post the full code, or an example of how to impliment that api call for a given network drive would be nice.
Cheers!
Andy
Ok this is written in vb 2005... -
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As Long, ByRef lpTotalNumberOfBytes As Long, ByRef lpTotalNumberOfFreeBytes As Long) As Long
-
Public Function GetFreeSpace(ByVal Drive As String) As Long
-
'returns free space in MB, formatted to two decimal places
-
'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB")
-
-
Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long
-
Dim iAns As Long
-
iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
-
lBytesTotal, lFreeBytes)
-
If iAns > 0 Then
-
Return BytesToMegabytes(lFreeBytes)
-
Else
-
Throw New Exception("Invalid or unreadable drive")
-
End If
-
End Function
-
Public Function GetTotalSpace(ByVal Drive As String) As String
-
'returns total space in MB, formatted to two decimal places
-
'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") & "MB")
-
Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long
-
Dim iAns As Long
-
iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
-
lBytesTotal, lFreeBytes)
-
If iAns > 0 Then
-
Return BytesToMegabytes(lBytesTotal)
-
Else
-
Throw New Exception("Invalid or unreadable drive")
-
End If
-
End Function
-
Private Function BytesToMegabytes(ByVal Bytes As Long) As Long
-
Dim dblAns As Double
-
dblAns = (Bytes / 1024) / 1024
-
BytesToMegabytes = Format(dblAns, "###,###,##0.00")
-
End Function
-
I call it like this: -
Dim jkp As Double = GetFreeSpace("\\123.45.678.90\C$") / 1024
-
Label5.Text = "DD2: " & Format(jkp, "###,###,##0.00") & " GB"
-
James
I don't think it's entirely clear so far what you want. Is this something you want to run on a server to monitor all the PC's connected to the network?
If you're just after information about the network drives connected to your PC, here's a much simpler example... - Private Sub Form_Click()
-
Dim fso As New FileSystemObject
-
Dim drv As Drive
-
For Each drv In fso.Drives
-
With drv
-
If .DriveType = Remote Then
-
Me.Print .DriveLetter, .DriveType, .AvailableSpace
-
End If
-
End With
-
Next
-
Set drv = Nothing
-
Set fso = Nothing
-
End Sub
You also haven't said what version of VB you're using. This is old VB6 code, but apart from the Sub declaration I believe it should work in later versions.
Nice one thanks.
I now have this running in a vb service on one of our servers, it warns us by email when disk levels of selected drives get to certain levels, and also issues warning decreases as the levels drop.
pretty basic, only the service at the ini, but i will make a gui when i get round to it.
Andy
Hey, it's good too hear you got it going alright.
Just out of curiosity, which technique did you end up using, API or FSO?
Hey, it's good too hear you got it going alright.
Just out of curiosity, which technique did you end up using, API or FSO?
I used the API call.
Seems to work well, I just have to make sure my service logs on as a network service with sufficient permissions to access the shared drives.
Cheers
-
Option Explicit
-
Private Declare Function GetDiskFreeSpace Lib “kernel32″ Alias _
-
“GetDiskFreeSpaceA” (ByVal lpRootPathName As String, _
-
lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
-
lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
-
-
Private Sub Command1_Click()
-
Dim Sectors As Long, Bytes As Long, FreeC As Long, TotalC As Long, Total As Long, Freeb As Long
-
GetDiskFreeSpace “E:\”, Sectors, Bytes, FreeC, TotalC
-
Me.AutoRedraw = True
-
Me.Print ” Path: C:\”
-
Me.Print ” Sectors per Cluster:” + Str$(Sectors)
-
Me.Print ” Bytes per sector:” + Str$(Bytes)
-
Me.Print ” Number Of Free Clusters:” + Str$(FreeC)
-
Me.Print ” Total Number Of Clusters:” + Str$(TotalC)
-
Total = TotalC * Sectors * Bytes
-
Me.Print ” Total number of bytes in path:” + Str$(Total)
-
Freeb = FreeC * Sectors * Bytes
-
Me.Print ” Free bytes:” + Str$(Freeb)
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chandra Mohan |
last post by:
Hi All,
I have a requirement to create the database with data and log files in
a different machine on the network.
Googling, I got a link which said Mapped drives do not work but UNC paths...
|
by: charles Collin |
last post by:
Hi,
My SQL server is short on disk space and I need to create a new instance
of SQLServer. I had another server running Linux with enough space left
so i create a new partition on it and shared...
|
by: David W. Fenton |
last post by:
I'm no stranger to this error message, but I have a client who is
experiencing it, but, fortunately, without any actual data
corruption, and it's driving them made. Their inability to grasp
that...
|
by: Jas Shultz |
last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework
installed. I have this problem with getting "out of disk space"
errors. I have 35 Gigs of disk space free.
It doesn't happen...
|
by: Skrol29 |
last post by:
Hello,
In order to encircle a problem of performance we have with our PHP
scripts, we were brought the make the following test. We take a
standard HTML page of our site, and we make a copy of...
|
by: NEWSGROUPS |
last post by:
I work for a large organization were my team has developed 2 very
substantial databases in Access 2000. These databases have been working fine
for the last 6 years with minimal issues or problems....
|
by: gary0gilbert |
last post by:
An unusual spin to this recurring disk or network error in a Terminal
Server environment. Access 2000, Terminal Server 2000, file server is
windows 2000. All users have a separate copy of the...
|
by: Lidia |
last post by:
Input: A computer name on the internal network
Out: Disk space total and remaining on all drives.
|
by: Mike |
last post by:
Is there a way to monitor a network drive for the space? I'm looking to
create something that will monitor the disk space on a network drive and
when it hits a certain level of free space (ie: 200...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |