命名为高架和非升高C#过程之间的管道IPC

发布于 2025-02-12 12:10:50 字数 531 浏览 1 评论 0原文

上下文:我编写了一个非高级Winforms应用程序,我想从中允许用户使用NTFS的MFT(主文件表)查询文件系统,因为它太快了!但是,从Windows 8或10或1809或其他东西开始,查询MFT需要过程高程,我不想运行我的应用程序高程。因此,我计划构建另一个可执行的可执行文件,以查询MFT。如果我这样做,那么我需要使用过程间通信(IPC)。好像命名的管道很简单(安全?)。

挑战:我编写了一个使用.NET的名为PipeServerStream名为PipeCleAntStream类来执行某些IPC的测试程序。当客户端和服务器进程同时运行升高或均未提高时,它们可以使用管道进行通信。但是,如果一个升高而另一个没有升高,则客户在尝试连接到服务器时抛出system.unauthorizedAccessexception例外。我有点期望。

我的问题:使用精心制作的system.io.pipes.pipesecurity对象构造服务器和客户端对象的简单问题?如果是这样,请帮助我为客户和服务器制作该对象。

Context: I wrote a non-elevated WinForms app, from which I want to allow the user to query the file system using NTFS' MFT (Master File Table) because it's so damn fast! However, starting with Windows 8 or 10 or 1809 or something or other, querying the MFT requires process elevation, and I don't want to run my app elevated. So I plan to build another executable, running elevated, to query the MFT. If I do that, then I need to use inter-process communication (IPC). Seems like named pipes is simple enough (and safe?).

The challenge: I wrote a test program that uses .NET's NamedPipeServerStream and NamedPipeClientStream classes to do some IPC. When client and server processes run either both elevated or both unelevated, they can communicate using the pipe. However, if one is elevated and the other isn't, then the client throws a System.UnauthorizedAccessException exception when trying to connect to the server. I kind of expected that.

My question: Is it a simple matter of constructing the server and client pipe objects with a carefully-crafted System.IO.Pipes.PipeSecurity object? If so, please help me to craft that object, both for the client and the server.

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

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

发布评论

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

评论(1

梦幻的心爱 2025-02-19 12:10:51

以下是我的工作,前两行是相关的行,其余的只是为了证明其使用。

var ps = new PipeSecurity();
ps.AddAccessRule(new PipeAccessRule(Environment.UserName, PipeAccessRights.ReadWrite, AccessControlType.Allow));

using(var pipe = new NamedPipeServerStream(
        pipeName: PipeName, 
        direction: PipeDirection.InOut, 
        maxNumberOfServerInstances: 1, 
        options: PipeOptions.None,
        transmissionMode: PipeTransmissionMode.Byte, 
        inBufferSize: 1024, 
        outBufferSize: 1024, 
        pipeSecurity: ps))
{
    ...
}

Below is what I got working, with the first two lines being the relevant ones and the rest just to demonstrate its use.

var ps = new PipeSecurity();
ps.AddAccessRule(new PipeAccessRule(Environment.UserName, PipeAccessRights.ReadWrite, AccessControlType.Allow));

using(var pipe = new NamedPipeServerStream(
        pipeName: PipeName, 
        direction: PipeDirection.InOut, 
        maxNumberOfServerInstances: 1, 
        options: PipeOptions.None,
        transmissionMode: PipeTransmissionMode.Byte, 
        inBufferSize: 1024, 
        outBufferSize: 1024, 
        pipeSecurity: ps))
{
    ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文