473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Enumeration of Servers

JD
I'm looking for a simple way to get a list of my server off of the network.
Primarily I'm looking for my SQLServers. In VB6 I'd use SQLDMO, but I was
looking for a pure .net solution. Anything?????
Nov 21 '05 #1
3 1318
I don't believe there will be a pure .net solution until yukon. Until then,
you will still have to use SQLDMO.

"JD" <da**********@walla.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
I'm looking for a simple way to get a list of my server off of the network. Primarily I'm looking for my SQLServers. In VB6 I'd use SQLDMO, but I was
looking for a pure .net solution. Anything?????

Nov 21 '05 #2
You can also P/Invoke the NetServerEnum() API.. it's faster and reference
free BUT it runs only on NT platform..

//***
using System;
using System.Runtime.InteropServices;

namespace NetServerEnum.Sample
{
public enum ServerType : uint
{
None = 0,
WorkStation = 0x1,
Server = 0x2,
SQLServer = 0x4,
DomainCtrl = 0x8,
DomainBAKCtrl = 0x10,
TimeSource = 0x20,
AFP = 0x40,
Novell = 0x80,
DomainMember = 0x100,
PrintQServer = 0x200,
DialInServer = 0x400,
XenixServer = 0x800,
ServerUNIX = XenixServer,
NT = 0x1000,
tWFW = 0x2000,
ServerMFPN = 0x4000,
ServerNT = 0x8000,
PotentialBrowser = 0x10000,
BackUpBroswer = 0x20000,
MasterBrowser = 0x40000,
DomainMaster = 0x80000,
ServerOSF = 0x100000,
ServerVMS = 0x200000,
Windows = 0x400000, // Windows95 and above
DFS = 0x800000, // Root of a DFS tree
ClusterNT = 0x1000000, // NT Cluster
TerminalServer = 0x2000000, // Terminal Server
DCE = 0x10000000, // IBM DSS
AlternateXport = 0x20000000, // rtn alternate transport
LocalListOnly = 0x40000000, // rtn local only
DomainEnum = 0x80000000,
All = 0xFFFFFFFF
}

public class NetworkManagement
{
private const Int32 MAX_PREFERRED_LENGTH = -1;
private const Int32 NERR_SUCCESS = 0;
private const Int32 ERROR_MORE_DATA = 234;

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
private struct SERVER_INFO_101
{
public Int32 dwPlatformID;
public string lpszServerName;
public Int32 dwVersionMajor;
public Int32 dwVersionMinor;
public Int32 dwType;
public string lpszComment;
}
[DllImport("netapi32.dll", SetLastError=true)]
private static extern void NetApiBufferFree
(
IntPtr lpBuffer
);
[DllImport("netapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
private static extern Int32 NetServerEnum
(
string servername,
Int32 level,
ref IntPtr bufptr,
Int32 prefmaxlen ,
ref Int32 entriesread,
ref Int32 totalentries,
ServerType servertype,
string domain,
ref Int32 resume_handle
);

public static string[] GetServerList(ServerType serverType)
{

IntPtr lpBuffer = IntPtr.Zero;
IntPtr lpTmpBuffer = IntPtr.Zero;
Int32 dwEntriesRead = 0;
Int32 dwTotalEntries = 0;
Int32 dwResumeHandle = 0;
SERVER_INFO_101 se101 = new SERVER_INFO_101();
Int32 nStructSize = 0;
string[] servers = null;

nStructSize = Marshal.SizeOf(se101);
Int32 iRet = NetServerEnum(null,
101,
ref lpBuffer,
MAX_PREFERRED_LENGTH,
ref dwEntriesRead,
ref dwTotalEntries,
serverType,
null,
ref dwResumeHandle);

if ((iRet == NERR_SUCCESS) && (iRet != ERROR_MORE_DATA))
{
servers = (string[])Array.CreateInstance(typeof(string), dwEntriesRead);
lpTmpBuffer = lpBuffer;
for (Int32 i = 0; i < dwEntriesRead; i++)
{
se101 = (SERVER_INFO_101)Marshal.PtrToStructure(lpTmpBuffe r,
se101.GetType());
servers[i] = se101.lpszServerName;
lpTmpBuffer = new IntPtr(lpTmpBuffer.ToInt32() + nStructSize);
}
}
if (!lpBuffer.Equals(IntPtr.Zero))
NetApiBufferFree(lpBuffer);

return servers;
}
}
}
//***
--
Best Regards
Yanick Lefebvre

"Marina" <so*****@nospam.com> a écrit dans le message de
news:ex**************@TK2MSFTNGP09.phx.gbl...
I don't believe there will be a pure .net solution until yukon. Until then, you will still have to use SQLDMO.

"JD" <da**********@walla.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
I'm looking for a simple way to get a list of my server off of the

network.
Primarily I'm looking for my SQLServers. In VB6 I'd use SQLDMO, but I was looking for a pure .net solution. Anything?????


Nov 21 '05 #3
.... and here's a VB version (sorry for the mistake..)
http://groups.google.com/groups?thre...TNGP11.phx.gbl
--
Best Regards
Yanick Lefebvre
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
1
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/>...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
3
by: eXt | last post by:
For a realtime-application (half an application at least, kind of a framework) I am working with I need a event managing system and naturally it must be fast. I have defined a set of available...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.