Print Search
帖子排序:    
帖子发起人: 大哥   发起时间: 2006-09-02 15:46 下午   回复: 5
tzh1080 离线,最后访问时间: 2007-3-21 12:33:11 大哥



发帖数前10位
男
注册: 2006-01-21
发 贴: 57
怎样设置SECURITY_ATTRIBUTES结构?
 2006-09-02, 15:46 下午

在Windows中,SECURITY_ATTRIBUTES结构是创建内核对象必须参数,而SECURITY_ATTRIBUTES结构中跟安全相关的参数实际上只有一个即lpSecurityDescriptor,这个参数一般会设置为NULL,表示使用系统默认安全性,然而我不想设置为系统默认的安全性,应该怎么弄啊?





IP 地址: 已记录   报告
stone 离线,最后访问时间: 2007-9-27 15:59:25 Stone Tao



发帖数前25位
注册: 2005-07-24
发 贴: 45
Re: 怎样设置SECURITY_ATTRIBUTES结构?
 2006-09-03, 11:40 上午

[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct STARTUPINFO
{
Int32 cb;
string lpReserved;
string lpDesktop;
string lpTitle;
Int32 dwX;
Int32 dwY;
Int32 dwXSize;
Int32 dwYSize;
Int32 dwXCountChars;
Int32 dwYCountChars;
Int32 dwFillAttribute;
Int32 dwFlags;
Int16 wShowWindow;
Int16 cbReserved2;
IntPtr lpReserved2;
IntPtr hStdInput;
IntPtr hStdOutput;
IntPtr hStdError;
}
[DllImport("kernel32.dll")]
static extern bool CreateProcess(string lpApplicationName,
string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes,
ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles,
uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,
[In] ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation);


public static void StartupNotepad()
{
const uint NORMAL_PRIORITY_CLASS = 0x0020;

bool retValue;
string Application = Environment.GetEnvironmentVariable("windir") + @"\Notepad.exe";
string CommandLine = @" c:\boot.ini";
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
STARTUPINFO sInfo = new STARTUPINFO();
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
pSec.nLength = Marshal.SizeOf(pSec);
tSec.nLength = Marshal.SizeOf(tSec);

//Open Notepad
retValue = CreateProcess(Application,CommandLine,
ref pSec,ref tSec,false,NORMAL_PRIORITY_CLASS,
IntPtr.Zero,null,ref sInfo,out pInfo);

Console.WriteLine("Process ID (PID): " + pInfo.dwProcessId);
Console.WriteLine("Process Handle : " + pInfo.hProcess);
}

IP 地址: 已记录   报告
tzh1080 离线,最后访问时间: 2007-3-21 12:33:11 大哥



发帖数前10位
男
注册: 2006-01-21
发 贴: 57
Re: 怎样设置SECURITY_ATTRIBUTES结构?
 2006-09-03, 21:02 下午

谢谢!不过我看着还是有点小晕,可能今天喝了点二锅头.那个CreateProcess也就ref了两个SECURITY_ATTRIBUTES, 怎么没见哪儿设置pSecurityDescriptor啊:)






IP 地址: 已记录   报告
stone 离线,最后访问时间: 2007-9-27 15:59:25 Stone Tao



发帖数前25位
注册: 2005-07-24
发 贴: 45
Re: 怎样设置SECURITY_ATTRIBUTES结构?
 2006-09-04, 09:46 上午
typedef struct _SECURITY_ATTRIBUTES { // sa
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;
nLength 是结构体的大小,自然是用sizeof取得了。lpSecurityDescriptor是安全描述符(一个C-Style的字符串)。 bInheritHandle他指出了安全描述的对象能否被新创建的进程继承。

lpSecurityDescriptor
A pointer to a security descriptor for the object that controls the sharing of it. If NULL is specified for this member, the object is assigned the default security descriptor of the calling process. This is not the same as granting access to everyone by assigning a NULL discretionary access control list (DACL). The default security descriptor is based on the default DACL of the access token belonging to the calling process. By default, the default DACL in the access token of a process allows access only to the user represented by the access token. If other users must access the object, you can either create a security descriptor with the appropriate access, or add ACEs to the DACL that grants access to a group of users.
Windows Me/98/95: The lpSecurityDescriptor member of this structure is ignored.
IP 地址: 已记录   报告
tzh1080 离线,最后访问时间: 2007-3-21 12:33:11 大哥



发帖数前10位
男
注册: 2006-01-21
发 贴: 57
Re: 怎样设置SECURITY_ATTRIBUTES结构?
 2006-09-04, 22:07 下午

Thank you!!!还是喝白开水爽快!



IP 地址: 已记录   报告
asdyzh 离线,最后访问时间: 2006-9-20 18:29:55 asdyzh

发帖数前200位
注册: 2006-09-20
发 贴: 1
Re: 怎样设置SECURITY_ATTRIBUTES结构?
 2006-09-20, 18:28 下午
我说 你不是大海吗 呵呵
IP 地址: 已记录   报告
合肥微软技术中心社区 » 技术讨论区 » .NET技术相关 » Re: 怎样设置SECURITY_ATTRIBUTES结构?

Powered by Community Server Powered by CnForums.Net