加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 04:29:14 所属栏目:大数据 来源:网络整理
导读:我的故事是,我正在设计一个必须与 Windows服务通信的新应用程序.经过多次研究,我得出结论,命名管道是推荐的方法( How do I send a string from one instance of my Delphi program to another?),但是,由于安全问题,似乎我无法使用Win7中的SendMessage或命名
我的故事是,我正在设计一个必须与 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;

解决方法

Windows Vista,7和2008强制使用命名管道,请参见例如 http://blogs.technet.com/b/nettracer/archive/2010/07/23/why-does-anonymous-pipe-access-fail-on-windows-vista-2008-windows-7-or-windows-2008-r2.aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读