Click here to Skip to main content
15,881,413 members
Home / Discussions / C#
   

C#

 
GeneralRe: Try-Catch performance cost Pin
leppie8-Jan-04 6:04
leppie8-Jan-04 6:04 
GeneralDetecting computers on a LAN Pin
Radoslav Bielik7-Jan-04 0:57
Radoslav Bielik7-Jan-04 0:57 
GeneralRe: Detecting computers on a LAN Pin
Mazdak7-Jan-04 1:46
Mazdak7-Jan-04 1:46 
GeneralRe: Detecting computers on a LAN Pin
Radoslav Bielik7-Jan-04 4:04
Radoslav Bielik7-Jan-04 4:04 
GeneralRe: Detecting computers on a LAN Pin
Mazdak7-Jan-04 5:12
Mazdak7-Jan-04 5:12 
GeneralRe: Detecting computers on a LAN Pin
Radoslav Bielik7-Jan-04 7:29
Radoslav Bielik7-Jan-04 7:29 
GeneralRe: Detecting computers on a LAN Pin
HAHAHA_NEXT7-Jan-04 7:45
HAHAHA_NEXT7-Jan-04 7:45 
GeneralRe: Detecting computers on a LAN Pin
Nick Seng7-Jan-04 14:52
Nick Seng7-Jan-04 14:52 
I asked this question a while back, and the answer I got was to use P\Invoke and NetServerEnum function.

Here's a snippet of the code I used.
[StructLayout(LayoutKind.Sequential)]
internal class ServerInfo
{
    public int platformid;
    [MarshalAs(UnmanagedType.LPWStr)]
    public string name;
    public int majorver,minorver;
    public int type;
    [MarshalAs(UnmanagedType.LPWStr)]
    public string comment;
}

class Class1
{
    [STAThread]
    static void Main(string[] args)
    {
        ArrayList arr = GetMachine();
        foreach (ServerInfo si in arr)
        {
            Console.WriteLine("{0} , {1}, {2}, {3}, {4}, {5}",si.name,si.comment,si.platformid,si.majorver,si.minorver,si.type);
    }

    [DllImport("Netapi32.dll")]
    private static extern int NetServerEnum(string servername, int level, out IntPtr buffer, int maxlen,
        out int entriesread, out int totalentries, uint servertype, string domain, int resumehandle);

    [DllImport("Netapi32.dll")]
    private static extern int NetApiBufferFree(IntPtr ptr);

    private static ArrayList GetMachine()
    {
        int eread,etot;
        IntPtr buffer;
        int l = 200;
        int size = Marshal.SizeOf(typeof(ServerInfo));
        int res = NetServerEnum(null,101,out buffer,-1,out eread, out etot,3/*4294967295*/,null,0);
        IntPtr p = buffer;
        ArrayList arr = new ArrayList(etot);

        for (int i = 0; i < eread; i++)
        {
            ServerInfo si = Marshal.PtrToStructure(p,typeof(ServerInfo)) as ServerInfo;
            arr.Add(si);

            p = (IntPtr)((int)p + size);
        }

        res = NetApiBufferFree(buffer);
        return arr;
    }
}




"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.

Support Bone

It's a weird Life
GeneralRe: Detecting computers on a LAN Pin
Radoslav Bielik7-Jan-04 21:37
Radoslav Bielik7-Jan-04 21:37 
GeneralRe: Detecting computers on a LAN Pin
Nick Seng7-Jan-04 22:25
Nick Seng7-Jan-04 22:25 
GeneralRe: Detecting computers on a LAN Pin
Radoslav Bielik7-Jan-04 22:53
Radoslav Bielik7-Jan-04 22:53 
GeneralRe: Detecting computers on a LAN Pin
HAHAHA_NEXT8-Jan-04 8:22
HAHAHA_NEXT8-Jan-04 8:22 
GeneralRe: Detecting computers on a LAN Pin
Radoslav Bielik8-Jan-04 8:30
Radoslav Bielik8-Jan-04 8:30 
GeneralThread and Processor Pin
devvvy7-Jan-04 0:24
devvvy7-Jan-04 0:24 
GeneralRe: Thread and Processor Pin
Philip Fitzsimons7-Jan-04 2:38
Philip Fitzsimons7-Jan-04 2:38 
GeneralRe: Thread and Processor Pin
devvvy7-Jan-04 2:43
devvvy7-Jan-04 2:43 
Generalreferenceadded Pin
meuri6-Jan-04 23:16
meuri6-Jan-04 23:16 
GeneralRe: referenceadded Pin
Niels Penneman7-Jan-04 9:34
Niels Penneman7-Jan-04 9:34 
GeneralRe: referenceadded Pin
meuri7-Jan-04 21:52
meuri7-Jan-04 21:52 
GeneralRe: referenceadded Pin
Niels Penneman8-Jan-04 6:16
Niels Penneman8-Jan-04 6:16 
GeneralRe: referenceadded Pin
Niels Penneman8-Jan-04 10:34
Niels Penneman8-Jan-04 10:34 
General.Net certification preparation Pin
r i s h a b h s6-Jan-04 19:03
r i s h a b h s6-Jan-04 19:03 
GeneralRe: .Net certification preparation Pin
Heath Stewart6-Jan-04 19:36
protectorHeath Stewart6-Jan-04 19:36 
GeneralRe: .Net certification preparation Pin
Mazdak6-Jan-04 22:34
Mazdak6-Jan-04 22:34 
GeneralRe: .Net certification preparation Pin
Bo Hunter7-Jan-04 3:19
Bo Hunter7-Jan-04 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.