引用的是Win32Security.dll
然后using Microsoft.Win32.Security;
代码如下:
运行到第10行时出现异常“未将对象引用设置到对象的实例”,大家帮忙
1    string PrinterName = "hp lj3200";            
2    try
3    {
4        SecurityDescriptor secDesc =SecurityDescriptor.GetNamedSecurityInfo(PrinterName, SE_OBJECT_TYPE.SE_PRINTER, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);
5        Dacl dacl = secDesc.Dacl;
6        
7        daclPrinter.AddAce(new AceAccessAllowed(new Sid("test"), AccessType.GENERIC_ALL));               
8           
9        secDesc.SetDacl(daclPrinter);
10       secDesc.SetNamedSecurityInfo(PrinterName, SE_OBJECT_TYPE.SE_PRINTER, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);
11       
12    }
13    catch (Exception ex)
14    {
15        MessageBox.Show(ex.Message, "error!");                
16    }