VB.NET - SHQueryRecycleBin 的问题

发布于 2024-11-19 12:37:59 字数 818 浏览 2 评论 0原文

我目前正在开发一个供我个人使用的应用程序。这个想法是,你可以打开它并获取计算机的所有类型的统计信息(回收站、驱动器、网络等等)。现在我正在使用 Win API 中的 SHQueryRecycleBin

虽然我有一些问题。我尝试过寻找 VB6 或 VB.NET 解决方案的过时解决方案,但这些解决方案根本不起作用。我使用了此源 并检索我使用的文件的大小和数量 此来源

我把它放在一个计时器中,在运行了 100 个刻度(正如我设置的那样)之后,我得到了这个错误:

File I/O of a structure with field 'cbSize' of type 'UInt32' is not valid.

cbSize 的类型是 UInteger ,它(显然)自动更改为 UInt32 - 我认为它是基于系统的。

您应该注意到,我使用的是 Windows 7 x86(64 位)。如果有比使用 Win API 更容易的此或另一段代码的解决方案,请告诉我。

我查看了 System.Management,但想要一个可以与大多数系统交互的防弹代码。

I'm currently working on an application for my personal use. The idea is that you can open it up and reach all kind of stats of your computer (Recycle bin, Drives, Network and much more). Now I was working with the SHQueryRecycleBin from Win API.

Though I have some problems. And I've tried to look over outdated solutions for VB6 or VB.NET solutions that simply didn't work. I used the code reference from this source and to retrieve the size and count of files I used this source.

I put it in an timer, and after those 100 ticks (as I set it) were ran, I got this error:

File I/O of a structure with field 'cbSize' of type 'UInt32' is not valid.

The type of cbSize is UInteger which (apparently) automatic changes to an UInt32 - I think it's based on the system.

You should note that I'm on an Windows 7 x86 (64-bit). If have an solution for this or another piece of code that is easier than use Win API, let me know.

I have looked at the System.Management but wanted an bullet proof code that could interact with most systems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风情万种。 2024-11-26 12:37:59

我没有方便测试的 vb.net,但以下代码在 vb6 中运行得很好:

在模块中:

Public Type SHRECYCLEBININFO
  cbSize As Long
  i64Size As Currency
  i64NumItems As Currency
End Type
Public Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHRECYCLEBININFO) As Long

在表单中:

Private Sub Command1_Click()
    Dim info As SHRECYCLEBININFO
    Dim res As Long

    info.cbSize = Len(info)
    res = SHQueryRecycleBin("C:\", info)
    MsgBox "size: " & (info.i64Size * 10000) & " bytes" & vbCrLf & "items: " & (info.i64NumItems * 10000)
End Sub

注意“货币”类型的使用 - 这是因为 vb6 没有正常的64 位整数的数据类型。类型 Currency 使用 8 个字节,但保留 4 位小数,因此乘以 10000 即可得到结果。

I don't have vb.net handy to test, but the following code works perfectly well in vb6:

In a module:

Public Type SHRECYCLEBININFO
  cbSize As Long
  i64Size As Currency
  i64NumItems As Currency
End Type
Public Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHRECYCLEBININFO) As Long

And in a form:

Private Sub Command1_Click()
    Dim info As SHRECYCLEBININFO
    Dim res As Long

    info.cbSize = Len(info)
    res = SHQueryRecycleBin("C:\", info)
    MsgBox "size: " & (info.i64Size * 10000) & " bytes" & vbCrLf & "items: " & (info.i64NumItems * 10000)
End Sub

Note the use of type "currency" - this is because vb6 doesn't have a normal data type for 64-bit integers. Type Currency is using 8 bytes, but keeps 4 decimal places, hence the multiplication by 10000 to get the results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文