taliesins / cassia

Automatically exported from code.google.com/p/cassia
1 stars 0 forks source link

Update documentation for GetServers to indicate dependency on NetBIOS and to suggest alternatives #44

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
hi i want to use this code the get all terminal servers.
i want to use this code in asp.net.

foreach (ITerminalServer server in _manager.GetServers(null))
{
  //
}

at the function GetServers i recieved the exeption wrong domain format. i have 
the same problme when i give the domainname theis function.

i use the cassia verasion 2.0.0.60

the as.net app run as a local administrator account

Original issue reported on code.google.com by thomas89...@googlemail.com on 16 Jul 2011 at 12:18

GoogleCodeExporter commented 8 years ago
Yeah, I'm a bit stumped on this one so far. I think it's a NetBIOS issue, but I 
haven't tried to track it down in depth yet. See this thread for suggestions:
http://groups.google.com/group/cassia-users/browse_thread/thread/fedeaf1ea74dbbe
0

Original comment by danports on 16 Jul 2011 at 2:49

GoogleCodeExporter commented 8 years ago

i have the same problem:

asp.net application
cassia.net v2.0.0.60
enumerate servers

netbios over tcp is active
mit full domainname is koelbel.local
i use the netbios name KOELBEL

i recieved the error:
wrong domainname

Original comment by thomas89...@googlemail.com on 17 Jul 2011 at 6:16

GoogleCodeExporter commented 8 years ago
See the first comment here: 
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383832(v=vs.85).aspx

Apparently the Computer Browser service (for NetBIOS) needs to be running on a 
DC for the WTSEnumerateServers to work, and that service is no longer running 
by default on 2008+. I think the best we can do here is document this and 
suggest that people use another method to enumerate RD servers (e.g. AD/LDAP 
queries).

Original comment by danports on 15 Feb 2012 at 3:59

GoogleCodeExporter commented 8 years ago

Original comment by danports on 26 Feb 2012 at 2:19

GoogleCodeExporter commented 8 years ago
The RDS API documentation now recommends NetServerEnum for this purpose:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa370623(v=vs.85).aspx

Original comment by danports on 19 Oct 2012 at 1:41

GoogleCodeExporter commented 8 years ago
Awesome library, but I also ran into the same issue. I changed NativeMethods to 
work correctly on 2008+ if you're interested in getting the change and updating 
the project.

Original comment by justinlc...@gmail.com on 28 Mar 2013 at 3:23

GoogleCodeExporter commented 8 years ago
Justin: Sure, send me a patch and I'll take a look at it. Did you use a 
different Win32 call in NativeMethods?

Original comment by danports on 29 Mar 2013 at 1:59

GoogleCodeExporter commented 8 years ago
Crashed on the same here now, found that they recomend netserverenum as noted 
in the bottom here:
http://msdn.microsoft.com/en-us/library/aa383832(v=vs.85).aspx
But very nice tool when used direct on servernames.

Original comment by asbj...@neslekkim.net on 3 May 2013 at 12:51

GoogleCodeExporter commented 8 years ago
Justin's suggestions -- documenting them here for now until I get a chance to 
review the code and make some changes:

in Impl/NativeMethods.cs, line 46:
        /* no longer works for Server 2008 and above
        [DllImport("Wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int WTSEnumerateServers([MarshalAs(UnmanagedType.LPTStr)] string pDomainName, int reserved,
                                                     int version, out IntPtr ppServerInfo, out int pCount);
         */
        //[DllImport("Wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [DllImport("Netapi32.dll", EntryPoint = "NetServerEnum")]
        public static extern Int32 NetServerEnum([MarshalAs(UnmanagedType.LPWStr)] String serverName, Int32 level, out IntPtr bufferPtr,
                                                UInt32 prefMaxLen, ref Int32 entriesRead, ref Int32 totalEntries,
                                                UInt32 serverType, [MarshalAs(UnmanagedType.LPWStr)] String domain,
                                                IntPtr handle);

        [DllImport("Netapi32.dll", EntryPoint = "NetApiBufferFree")]
        public static extern UInt32 NetApiBufferFree(IntPtr buffer);

in Impl/NativeMethodsHelper.cs, line 142:
        public static IList<WTS_SERVER_INFO> EnumerateServers(string domainName)
        {
            IntPtr ppServerInfo;
            int count = 0;

            int totalEntries = 0;
            UInt32 MAX_PREFERRED_LENGTH = 0xFFFFFFFF;
            //all servers
            UInt32 ServerType = 0xFFFFFFFF;
            //only valid up to 2008.
            //if (NativeMethods.WTSEnumerateServers(domainName, 0, 1, out ppServerInfo, out count) == 0)
            int result = NativeMethods.NetServerEnum(null, 100, out ppServerInfo, MAX_PREFERRED_LENGTH, ref count, ref totalEntries, ServerType, domainName, IntPtr.Zero);
            if (result == 234)
            {
                throw new Win32Exception();
            }
            try
            {
                return PtrToStructureList<WTS_SERVER_INFO>(ppServerInfo, count);
            }
            finally
            {
                NativeMethods.WTSFreeMemory(ppServerInfo);
            }
        }

Original comment by danports on 6 Sep 2013 at 1:54