如何使用GetDiskFreeSpace

cytsq159610 2003-10-20 05:44:38
各位大侠,在本机通过GetDiskFreeSpace可以获得本机磁盘容量,
但如何使用GetDiskFreeSpace来得到局域网内某一台机器的磁盘容量?
是否要对lpRootPathName进行修改啊
怎么修改?(假如你已经知道了IP地址了)
...全文
106 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-10-22
  • 打赏
  • 举报
回复
就是这样
online 2003-10-22
  • 打赏
  • 举报
回复
如果硬盘共享,依次盘符会是h:,k:,l:
sdrive="h:\"即可
如果有driver控件,会自动列出所有的盘符
sDrive = Left$(DrvSelect.Drive, 1)
sDrive = sDrive & ":\"
cytsq159610 2003-10-22
  • 打赏
  • 举报
回复
各位,我想知道怎么给sdrive赋值啊,如果赋值为“c:\”,那是在访问本机的c盘剩余空间啊,如果要获得局域网中其它机器的c盘剩余空间,又该怎么做啊?顺便说一下,机器硬盘已经共享了。
麻烦大家详细告知一下啊!!
online 2003-10-21
  • 打赏
  • 举报
回复
但如何使用GetDiskFreeSpace来得到局域网内某一台机器的磁盘容量?
是否要对lpRootPathName进行修改啊
怎么修改?(假如你已经知道了IP地址了)

将机器的硬盘共享即可
知道ip好像不行
online 2003-10-21
  • 打赏
  • 举报
回复
Option Explicit

' API声明
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 Form_Load()
GetDriveInfo
End Sub

' 选中一个驱动器时
Private Sub drvSelect_Change()
GetDriveInfo
End Sub

' 获取磁盘剩余空间信息并显示在相应的标签中
Private Function GetDriveInfo()
Dim sDrive As String
Dim lBytes As Long
Dim lMBFree As Double
Dim lMBTotal As Double
Dim lSecPerClust As Long ' 扇区每簇
Dim lBytePerSect As Long ' 字节每扇区
Dim lNumFreeClust As Long ' 空白簇的数目
Dim lTotalNumClust As Long ' 簇的总数

' 获取盘符
sDrive = Left$(DrvSelect.Drive, 1)
sDrive = sDrive & ":\"
' 调用API函数返回剩余空间
lBytes = GetDiskFreeSpace(sDrive, lSecPerClust, lBytePerSect, lNumFreeClust, lTotalNumClust)
' 转换以兆为单位
lMBFree = ((lSecPerClust * lNumFreeClust) / 1024) * lBytePerSect / 1024
lMBTotal = ((lSecPerClust * lTotalNumClust) / 1024) * lBytePerSect / 1024
' 显示信息
lblSecPerClust.Caption = lSecPerClust & " Sectors/Cluster"
lblBytePerSect.Caption = lBytePerSect & " Bytes/Sector"
lblNumFreeClust.Caption = lNumFreeClust & " Free Clusters"
lblTotalNumClust.Caption = lTotalNumClust & " Total Clusters"
lblTotalSpace.Caption = lMBTotal & " MB Total Space"
lblSpaceFree.Caption = lMBFree & " MB Free on Drive " & DrvSelect.Drive
End Function

hhjjhjhj 2003-10-20
  • 打赏
  • 举报
回复
Sub ShowSpaceInfo(drvpath)
Dim fs, d, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)))
s = "Drive " & d.DriveLetter & ":"
s = s & vbCrLf
s = s & "Total Size: " & FormatNumber(d.TotalSize / 1024, 0) & " Kbytes"
s = s & vbCrLf
s = s & "Available: " & FormatNumber(d.AvailableSpace / 1024, 0) & " Kbytes"
MsgBox s
End Sub
rainstormmaster 2003-10-20
  • 打赏
  • 举报
回复
应该用GetDiskFreeSpaceex获得大磁盘容量
参考
http://asp3.6to23.com/tgoodnet/xtmblw/IT/VB.htm

Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧