示例#1
0
        apiNetAddGroup(
            string servername,
            string groupname,
            string description
            )
        {
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            LOCALGROUP_INFO_1 lg1 = new LOCALGROUP_INFO_1();
            lg1.name = groupname;
            lg1.comment = description;
            UInt32 parm_err = 0;

            IntPtr bufptr = Marshal.AllocHGlobal(Marshal.SizeOf(lg1));
            IntPtr bufptr_parm_err = Marshal.AllocHGlobal(Marshal.SizeOf(parm_err));

            try
            {
                Marshal.StructureToPtr(lg1, bufptr, false);
                result = (uint)NetLocalGroupAdd(servername, 1, bufptr, bufptr_parm_err);
            }
            catch (Exception)
            {
                result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE;
            }
            finally
            {
                Marshal.DestroyStructure(bufptr, lg1.GetType());
                Marshal.FreeHGlobal(bufptr);
                Marshal.FreeHGlobal(bufptr_parm_err);

            }
            return result;
        }
示例#2
0
        NetEditGroupDescription(
            string servername,
            string groupname,
            string description
            )
        {
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            if (String.IsNullOrEmpty(servername))
            {
                servername = null;
            }
            if (String.IsNullOrEmpty(groupname))
            {
                groupname = null;
            }
            if (String.IsNullOrEmpty(description))
            {
                description = null;
            }

            LOCALGROUP_INFO_1 groupinfo_1 = new LOCALGROUP_INFO_1();
            groupinfo_1.comment = description;

            IntPtr bufptr = IntPtr.Zero;
            bufptr = Marshal.AllocHGlobal(Marshal.SizeOf(groupinfo_1));

            try
            {
                if (!NetApiInitCalled)
                {
                    result = NetApiInit();
                    if (result != (uint)LUGAPI.WinError.ERROR_SUCCESS)
                    {
                        return result;
                    }

                    NetApiInitCalled = true;
                }

                Marshal.StructureToPtr(groupinfo_1, bufptr, false);

                result = (uint)NetLocalGroupSetInfo(servername, groupname, 1, bufptr, IntPtr.Zero);
            }
            catch (Exception)
            {
                result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE;
            }
            finally
            {
                Marshal.DestroyStructure(bufptr, groupinfo_1.GetType());
                Marshal.FreeHGlobal(bufptr);
            }

            return result;

        }