CreateNamedPipe時在Win 7。如何不工作屬性改變安全屬性使用C#CreateNamedPipe時在Win 7。如何不工作來改變安全使用C#
[StructLayout(LayoutKind.Sequential)] private struct SECURITY_ATTRIBUTES { public int nLength; public IntPtr lpSecurityDescriptor; public int bInheritHandle; }
public bool CreatePipe() { // Make a named pipe in message mode
IntPtr securityDescriptorPtr = IntPtr.Zero;
int securityDescriptorSize = 0;
bool result = ConvertStringSecurityDescriptorToSecurityDescriptor(
LOW_INTEGRITY_SSL_SACL, SDDL_REVISION_1, out securityDescriptorPtr, out securityDescriptorSize);
if (!result)
throw new Win32Exception(Marshal.GetLastWin32Error());
SECURITY_ATTRIBUTES securityAttributes = new SECURITY_ATTRIBUTES();
securityAttributes.nLength = Marshal.SizeOf(securityAttributes);
securityAttributes.bInheritHandle = 1;
securityAttributes.lpSecurityDescriptor = securityDescriptorPtr;
_handle = CreateNamedPipe(_pipeName,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
PIPE_SERVER_BUFFER_SIZE,
PIPE_SERVER_BUFFER_SIZE,
NMPWAIT_WAIT_FOREVER,
securityAttributes);
// Make sure we got a good one
if (_handle.IsInvalid)
{
Debug.WriteLine("Could not create the pipe (" + _pipeName + ") - os returned " +
Marshal.GetLastWin32Error());
return false;
}
return true;
}
由於安全屬性它給出例外。爲什麼是這樣? 我得到了 錯誤bool result = ConvertStringSecurityDescriptorToSecurityDescriptor( LOW_INTEGRITY_SSL_SACL,SDDL_REVISION_1,out securityDescriptorPtr,out securityDescriptorSize); 線,是指定的數據類型是無效的(Win32除外)
你應該提供更多的細節,例如拋出什麼異常,爲什麼不使用System.IO.Pipes類的NamedPipeServerStream和NamedPipeClientStream,它們是否工作? – 2010-10-30 11:50:11