程序外函数调用和返回的 HANDLE 类型(Windows C++)
我需要使用最大权限(NT AUTHORY\System)从在同一本地计算机上以低特权模式(NT AUTHORY\Network service)运行的其他进程(IIS7模块工作进程)调用一个函数。
IIS 模块将调用该函数并传递一些文本(用户名),并且该函数需要返回 HADNLE 类型,该函数将在使用 CloseHandle 函数处理后关闭。
(函数:LogonUser http://msdn.microsoft.com /en-us/library/aa378184(VS.85).aspx )
最好的方法是什么? COM+、共享内存、命名管道?我没有任何编程经验,所以我需要一些帮助。我不知道如何使用命名管道传递句柄类型? (我只看到仅传递基于文本的消息,而不传递指针或其他数据类型的示例)。
I need to call one function using maximum privileges (NT AUTHORY\System) from other process (IIS7 module work process) running in same local computer in much less privileged mode (NT AUTHORY\Network service).
IIS module will call that function passing some text (user name) and that function need to return HADNLE type witch will be closed after process using CloseHandle function.
( function: LogonUser http://msdn.microsoft.com/en-us/library/aa378184(VS.85).aspx )
What is the best way to do this? COM+, shared memory, named pipes? I don't have any experience in this programming, so i need some help. I don't know how to pass handle type with named pipes? (i saw only examples that are passing only text based messages, not pointers or other data types).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
句柄不可跨会话边界使用。而且我不能 100% 确定它可以跨进程边界用于所有类型的句柄。
例如,最好使用管道来通知以提升的权限运行的其他进程以获得自己的句柄并执行您想要的任何操作。
至于进行沟通的最佳方法是什么,这实际上取决于您的具体需求以及您在每种方面的具体经验水平。
Handles are not usable across the session boundary. And I'm not 100% sure it is usable across the process boundary for all types of handles.
It's better to for example use pipes to notify the other process who is running with elevated priveleges to get it's own handle and perform whatever operation you want.
As to what is the best method to do the communication, this really depends on your exact needs and your exact experience level in each way.
仅供参考,HANDLE 在 Windows 中只是一个 32 位整数值。它不是指向内存位置的指针。
Just FYI, a HANDLE is just a 32-bit integer value in Windows. It is not a pointer to a memory location.
您不能将句柄传递给另一个进程,句柄是进程本地的。但您可以使用 DuplicateHandle 创建克隆您的句柄供另一个进程使用。只有其他进程可以使用副本。另一个进程负责对其调用
CloseHandle
。You can't pass a handle to another process, handles are process local. But you can use DuplicateHandle to create a clone of your handle for use by another process. Only the other process can use the duplicate. The other process is responsible for calling
CloseHandle
on it.