delphi - 从 Windows 服务到客户端应用程序的命名管道

标签 delphi windows-services desktop-application c++builder named-pipes

我的故事是,我正在设计一个必须与 Windows 服务通信的新应用程序。经过大量研究,我得出的结论是命名管道是推荐的方法( How do I send a string from one instance of my Delphi program to another? ),但是,由于安全问题,我似乎无法在 Win7 中使用 SendMessage 或命名管道...消息永远不会到达外部为应用程序提供服务。

我正在使用 Russell Libby 的命名 Pipe 组件,该组件可以在正常桌面应用程序之间正常工作,但 Windows 服务似乎对解决方案造成了影响。进一步的研究告诉我,也许可以开放双方的安全性以让他们进行通信,但是,我对此的知识水平充其量只是最低限度,并且我无法弄清楚可能的 API 调用.

基于Delphi组件pipes.pas,需要做什么才能打开这个宝贝以便双方可以开始交谈?我确信 Pipes.pas 文件中的以下两个函数可以识别安全属性,有人可以帮助我吗?

谢谢!

procedure InitializeSecurity(var SA: TSecurityAttributes);
var
  sd: PSecurityDescriptor;
begin

  // Allocate memory for the security descriptor
  sd := AllocMem(SECURITY_DESCRIPTOR_MIN_LENGTH);

  // Initialize the new security descriptor
  if InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION) then
  begin
    // Add a NULL descriptor ACL to the security descriptor
    if SetSecurityDescriptorDacl(sd, True, nil, False) then
    begin
      // Set up the security attributes structure
      SA.nLength := SizeOf(TSecurityAttributes);
      SA.lpSecurityDescriptor := sd;
      SA.bInheritHandle := True;
    end
    else
      // Failed to init the sec descriptor
      RaiseWindowsError;
  end
  else
    // Failed to init the sec descriptor
    RaiseWindowsError;

end;

procedure FinalizeSecurity(var SA: TSecurityAttributes);
begin

  // Release memory that was assigned to security descriptor
  if Assigned(SA.lpSecurityDescriptor) then
  begin
    // Reource protection
    try
      // Free memory
      FreeMem(SA.lpSecurityDescriptor);
    finally
      // Clear pointer
      SA.lpSecurityDescriptor := nil;
    end;
  end;

end;

最佳答案

关于delphi - 从 Windows 服务到客户端应用程序的命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6684387/

相关文章:

delphi - 为什么只有一个电子邮件地址不正确时 IdSMTP.Send 会失败?

asp.net - Windows服务SQL超时异常

c# - 替代 "Allow service to interact with desktop"?

php - 将 PHP 项目转换为桌面应用程序

firebase - 如何将 flutter windows 应用程序与 firebase 集成?

delphi - 有没有办法以编程方式选择 VirtualTreeView 中的节点?

Delphi - 大量节点下的虚拟字符串树慢速 GetText 方法

windows - 特定应用程序的文件权限

python - 从 python 作为子进程启动服务

java - 什么是 Java Hybrid - Applet + 应用程序?