apiNetAddGroup( string servername, string groupname ) { uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS; LOCALGROUP_INFO_0 lg0 = new LOCALGROUP_INFO_0(); lg0.lgrpi0_name = groupname; UInt32 parm_err = 0; IntPtr bufptr = Marshal.AllocHGlobal(Marshal.SizeOf(lg0)); IntPtr bufptr_parm_err = Marshal.AllocHGlobal(Marshal.SizeOf(parm_err)); try { Marshal.StructureToPtr(lg0, bufptr, false); result = (uint)NetLocalGroupAdd(servername, 0, bufptr, bufptr_parm_err); } catch (Exception) { result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE; } finally { Marshal.DestroyStructure(bufptr, lg0.GetType()); Marshal.FreeHGlobal(bufptr); Marshal.FreeHGlobal(bufptr_parm_err); } return result; }
NetRenameGroup( string servername, string oldgroupname, string groupname ) { uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS; if (String.IsNullOrEmpty(servername)) { servername = null; } if (String.IsNullOrEmpty(oldgroupname)) { oldgroupname = null; } if (String.IsNullOrEmpty(groupname)) { groupname = null; } LOCALGROUP_INFO_0 localgrouinfo_0 = new LOCALGROUP_INFO_0(); localgrouinfo_0.lgrpi0_name = groupname; IntPtr bufptr = IntPtr.Zero; bufptr = Marshal.AllocHGlobal( Marshal.SizeOf(localgrouinfo_0)); try { if (!NetApiInitCalled) { result = NetApiInit(); if (result != (uint)LUGAPI.WinError.ERROR_SUCCESS) { return result; } NetApiInitCalled = true; } Marshal.StructureToPtr(localgrouinfo_0, bufptr, false); result = (uint)NetLocalGroupSetInfo( servername, oldgroupname, 0, bufptr, IntPtr.Zero); } catch (Exception) { result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE; } finally { Marshal.DestroyStructure( bufptr, localgrouinfo_0.GetType()); Marshal.FreeHGlobal(bufptr); } return result; }