ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSFinger/Net.cs
Revision: 718
Committed: 2006-03-30T02:50:17-08:00 (19 years, 3 months ago) by douglas
File size: 3355 byte(s)
Log Message:
Getting somewhere!

File Contents

# Content
1 // Douglas Thrift
2 //
3 // CCS Computer Science
4 //
5 // Win32 Network Management Wrapper
6
7 using System;
8 using System.Runtime.InteropServices;
9
10 public static class Net
11 {
12 [StructLayout(LayoutKind.Sequential)]
13 public class NET_DISPLAY_USER
14 {
15 [MarshalAs(UnmanagedType.LPWStr)]
16 public string usri1_name;
17 [MarshalAs(UnmanagedType.LPWStr)]
18 public string usri1_comment;
19 public uint usri1_flags;
20 [MarshalAs(UnmanagedType.LPWStr)]
21 public string usri1_full_name;
22 public uint usri1_user_id;
23 public uint usri1_next_index;
24 }
25
26 [StructLayout(LayoutKind.Sequential)]
27 public class USER_INFO_11
28 {
29 [MarshalAs(UnmanagedType.LPWStr)]
30 public string usri11_name;
31 [MarshalAs(UnmanagedType.LPWStr)]
32 public string usri11_comment;
33 [MarshalAs(UnmanagedType.LPWStr)]
34 public string usri11_usr_comment;
35 [MarshalAs(UnmanagedType.LPWStr)]
36 public string usri11_full_name;
37 public uint usri11_priv;
38 public uint usri11_auth_flags;
39 public uint usri11_password_age;
40 [MarshalAs(UnmanagedType.LPWStr)]
41 public string usri11_home_dir;
42 [MarshalAs(UnmanagedType.LPWStr)]
43 public string usri11_parms;
44 public uint usri11_last_logon;
45 public uint usri11_last_logoff;
46 public uint usri11_bad_pw_count;
47 public uint usri11_num_logons;
48 [MarshalAs(UnmanagedType.LPWStr)]
49 public string usri11_logon_server;
50 public uint usri11_country_code;
51 [MarshalAs(UnmanagedType.LPWStr)]
52 public string usri11_workstations;
53 public uint usri11_max_storage;
54 public uint usri11_units_per_week;
55 public IntPtr usri11_logon_hours;
56 public uint usri11_code_page;
57 }
58
59 [DllImport("Netapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "NetQueryDisplayInformation")]
60 public static extern uint QueryDisplayInformation(string ServerName, uint Level, uint Index, uint EntriesRequested, uint PreferredMaximumLength, out uint ReturnedEntryCount, out IntPtr SortedBuffer);
61
62 public static uint QueryDisplayInformation(string ServerName, uint Level, uint Index, uint EntriesRequested, uint PreferredMaximumLength, out uint ReturnedEntryCount, out NET_DISPLAY_USER[] SortedBuffer)
63 {
64 IntPtr pointer;
65 uint value = QueryDisplayInformation(ServerName, Level, Index, EntriesRequested, PreferredMaximumLength, out ReturnedEntryCount, out pointer);
66
67 SortedBuffer = new NET_DISPLAY_USER[ReturnedEntryCount];
68
69 for (long index = 0; index != ReturnedEntryCount; ++index)
70 {
71 IntPtr pointer_ = new IntPtr(pointer.ToInt64() + Marshal.SizeOf(typeof(NET_DISPLAY_USER)) * index);
72
73 SortedBuffer[index] = (NET_DISPLAY_USER)Marshal.PtrToStructure(pointer_, typeof(NET_DISPLAY_USER));
74 }
75
76 ApiBufferFree(pointer);
77
78 return value;
79 }
80
81 [DllImport("Netapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "NetUserGetInfo")]
82 public static extern uint UserGetInfo(string servername, string username, uint level, out IntPtr bufptr);
83
84 public static uint UserGetInfo(string servername, string username, uint level, out USER_INFO_11 bufptr)
85 {
86 IntPtr pointer;
87 uint value = UserGetInfo(servername, username, level, out pointer);
88
89 bufptr = new USER_INFO_11();
90
91 Marshal.PtrToStructure(pointer, bufptr);
92
93 ApiBufferFree(pointer);
94
95 return value;
96 }
97
98 [DllImport("Netapi32.dll", EntryPoint = "NetApiBufferFree")]
99 public static extern uint ApiBufferFree(IntPtr buffer);
100 }