开发者

When accessing a logical drive's space status, the total drive results are correct, but the free space results are not

开发者 https://www.devze.com 2023-01-19 09:22 出处:网络
The problem appears to be with the The Win32_LogicalDisk class\' free space property as it is showing only what the currently logged in user has rights to, 开发者_StackOverflownot what free space actu

The problem appears to be with the The Win32_LogicalDisk class' free space property as it is showing only what the currently logged in user has rights to, 开发者_StackOverflownot what free space actually exists.

Example code, though not entirely necc:

Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='Z:'")

' server share, total disk size, total disk free, percent free
tmpStatus = tmpStatus & arrShares(i) & "," & FormatNumber((objLogicalDisk.size / GBCONVERSION),,-1) & "," & _
FormatNumber((objLogicalDisk.FreeSpace / GBCONVERSION),,-1) & "," & _
((objLogicalDisk.FreeSpace / GBCONVERSION) / (objLogicalDisk.size / GBCONVERSION) * 100) & "@"

NOTE: This is for a virtual server network share, so the drive type is 4

Is there a better way? Again, the total drive space is correct, but the free space is not since from what I've found on MSDN it uses the current user's rights to determine free space. There must be another/better way.


Ok so the trick seems to be to use the file system object disk properties instead of the w32_logicaldisk properties. Using FSO, all of the numbers are accurate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号