我的故事是,我正在设计一个必须与 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
关于delphi - 从 Windows 服务到客户端应用程序的命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6684387/