VB.NET - 调用 Kernel32.DLL 的 Wow64DisableWow64FsRedirection

发布于 2024-09-27 19:12:32 字数 788 浏览 6 评论 0原文

查看 Microsoft 的 Wow64DisableWow64FsRedirection 页面,我看到一些 C 代码。如果您想调用此函数并且它是从 VB.net 恢复的,该怎么办?

到目前为止,我已经这样做了:

 <Runtime.InteropServices.DllImport("KERNEL32.DLL",  EntryPoint:="Wow64DisableWow64FsRedirection")> _
Public Shared Function DisableWow64Redirection() As Boolean
End Function

并且我对 Revert 兄弟函数也做了同样的事情。

我这样称呼它:

DisableWow64Redirection()

这似乎有效,因为我调用的 shell 命令实际上在 system32 中找到了它的 exe,但我不确定恢复,它是否需要参数?此还原页面似乎需要我从禁用中获取输出并将其插入到恢复调用中。听起来对吗?如何更改 DLLimport 以接受布尔值并在 Kernal32.DLL 函数中实际使用它?

谢谢!

Looking at Microsoft's page on Wow64DisableWow64FsRedirection, I see some C code. What if you want to call this function and it's revert from VB.net?

So far I have done this:

 <Runtime.InteropServices.DllImport("KERNEL32.DLL",  EntryPoint:="Wow64DisableWow64FsRedirection")> _
Public Shared Function DisableWow64Redirection() As Boolean
End Function

And I do likewise for the Revert brother function.

I call it like so:

DisableWow64Redirection()

This seems to work, as the shell command I call after actually finds its exe in system32, but I am not sure about the Revert, does it need a parameter? This Revert page seems to want me to take the output from disable and plug it into the revert call. Does that sound right? How do I change my DLLimport to take in a boolean and actually use it in the Kernal32.DLL function?

Thanks!

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

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

发布评论

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

评论(2

〗斷ホ乔殘χμё〖 2024-10-04 19:12:32

您可以将函数定义更改为

<DllImport("kernel32.dll", EntryPoint := "Wow64DisableWow64FsRedirection")> _
Public Shared Function DisableWow64Redirection(ByRef output As IntPtr) As Boolean

并定义 Revert(),如下所示:

<DllImport("kernel32.dll", EntryPoint := "Wow64RevertWow64FsRedirection")> _
Public Shared Function RevertWow64Redirection(ByRef handle As IntPtr) As Boolean

您可以像这样调用它们:

Dim handle As IntPtr
DisableWow64Redirection(handle)
RevertWow64Redirection(handle)

我不是 VB.NET 人员,所以也许某些语法不正确 - 重要的是您提供了一个引用参数IntPtr 类型,映射到 PVOID 本机类型。您需要保留它,并将相同的值传递给 Revert()。

You could change your function definition to

<DllImport("kernel32.dll", EntryPoint := "Wow64DisableWow64FsRedirection")> _
Public Shared Function DisableWow64Redirection(ByRef output As IntPtr) As Boolean

and define Revert() like so:

<DllImport("kernel32.dll", EntryPoint := "Wow64RevertWow64FsRedirection")> _
Public Shared Function RevertWow64Redirection(ByRef handle As IntPtr) As Boolean

You'd invoke these like so:

Dim handle As IntPtr
DisableWow64Redirection(handle)
RevertWow64Redirection(handle)

I'm not a VB.NET guy, so maybe some syntax is incorrect - the important thing is that you provide a reference parameter of IntPtr type, which maps to the PVOID native type. You'll want to hang on to it, and pass the same value to Revert().

像极了他 2024-10-04 19:12:32

声明是错误的,它需要一个 (ByRef oldValue As IntPtr) 参数。您需要将其传递给恢复函数。

但是,您无法在 .NET 程序中安全地使用它。它还会影响 CLR,它将无法再找到 .NET 框架程序集。您无法预测它们何时加载。肯定有更好的方法来完成你所需要的,对此提出一个新问题。

The declaration is wrong, it takes a (ByRef oldValue As IntPtr) argument. Which you need to pass to the revert function.

However, you cannot safely use this in a .NET program. It also affects the CLR, it won't be able to find .NET framework assemblies anymore. You cannot predict when they get loaded. There are surely better ways to accomplish what you need, start a new question about that.

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