none
请问在WebService里面使用WMI的SetSecurityDescriptor方法出现1307错误代码的问题 RRS feed

  • 问题

  • 我在WebService里面使用WMI的SetSecurityDescriptor方法出现1307错误代码,请问是什么原因呢?我在Web.config里面已经设置了管理员权限的<identity impersonate="true" userName="administrator" password="1"/>,这段代码在WINFORM里面可以执行成功的!

    代码:

    ManagementObject mo = new ManagementObject(string.Format("Win32_LogicalFileSecuritySetting.Path='{0}'", Path));
                ManagementBaseObject outParams = mo.InvokeMethod("GetSecurityDescriptor", null, null);

                if ((uint)outParams.Properties["ReturnValue"].Value != 0)
                    return "该目录没有共享";
                ManagementBaseObject Descriptor = (ManagementBaseObject)outParams.Properties["Descriptor"].Value;

                List<ManagementBaseObject> newDacl = new List<ManagementBaseObject>();
                if (UserName.Trim() != "Administrator")
                    newDacl.AddRange((ManagementBaseObject[])Descriptor.Properties["Dacl"].Value);

                //增加Everyone用户
                ManagementClass trustee = new ManagementClass("win32_trustee");
                trustee.Properties["Name"].Value = "Everyone";
                trustee.Properties["Domain"].Value = null;

                //设置只读/运行权限
                ManagementClass ace = new ManagementClass("win32_ace");
                ace.Properties["AccessMask"].Value = AccessPrivileges.FileReadData | AccessPrivileges.FileReadAttributes | AccessPrivileges.FileReadEA
                    | AccessPrivileges.ReadControl | AccessPrivileges.FileExecute;
                ace.Properties["AceFlags"].Value = AceFlags.ObjectInheritAce | AceFlags.ContainerInheritAce | AceFlags.NoPropagateInheritAce;
                ace.Properties["AceType"].Value = AceType.AccessAllowed;
                ace.Properties["Trustee"].Value = trustee;
                newDacl.Add(ace);
               
                ace.Properties["AceFlags"].Value = AceFlags.ObjectInheritAce | AceFlags.ContainerInheritAce | AceFlags.NoPropagateInheritAce;
                ace.Properties["AceType"].Value = AceType.AccessAllowed;
                ace.Properties["Trustee"].Value = trustee;
                newDacl.Add(ace);
                ManagementBaseObject inParams = mo.GetMethodParameters("SetSecurityDescriptor");
                Descriptor.Properties["Dacl"].Value = newDacl.ToArray();

                inParams["Descriptor"] = Descriptor;
                ManagementBaseObject ret = mo.InvokeMethod("SetSecurityDescriptor", inParams, null);
                
                uint returnValue = (uint)ret.Properties["ReturnValue"].Value;

     

    2010年3月27日 4:04

答案