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

Kri*_*fer 10 delphi windows-services desktop-application c++builder named-pipes

我的故事是我正在设计一个必须与Windows服务通信的新应用程序.经过大量研究后,我得出结论,命名管道是推荐的方法(如何从我的Delphi程序的一个实例发送一个字符串到另一个?)但是,似乎我不能在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;
Run Code Online (Sandbox Code Playgroud)