| | |
problem with NetServerEnum
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Inorder to list all the workstations on a LAN, i have used NetServerEnum() after importing it.
On running the program, it seemed to work fine. The two existing machines were detected correctly.
However, i want the list to be refreshed whenever required (some refresh button). So i detached the wire of the other computer from the switch, rendering only a single computer on the LAN.
Now, when i ran the program, it still lists out the disconnected machine.
How to solve this out?
The code is as follows :
On running the program, it seemed to work fine. The two existing machines were detected correctly.
However, i want the list to be refreshed whenever required (some refresh button). So i detached the wire of the other computer from the switch, rendering only a single computer on the LAN.
Now, when i ran the program, it still lists out the disconnected machine.
How to solve this out?
The code is as follows :
C# Syntax (Toggle Plain Text)
namespace LanIpAddresses { class NetApi { [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 ); } class EnumerateLanMachines { public const UInt32 SUCCESS = 0; public const UInt32 FAIL = 234; public const UInt32 MAX_PREFERRED_LENGTH = 0xFFFFFFFF; //public ArrayList machines = new ArrayList ( ); enum ServerTypes : uint { WorkStation = 0x00000001, Server = 0x00000002 } [StructLayout ( LayoutKind.Sequential, CharSet = CharSet.Auto )] public struct MachineInfo { [MarshalAs ( UnmanagedType.U4 )] public UInt32 platformId; [MarshalAs ( UnmanagedType.LPWStr )] public String serverName; } public enum Platform { PLATFORM_ID_DOS = 300, PLATFORM_ID_OS2 = 400, PLATFORM_ID_NT = 500, PLATFORM_ID_OSF = 600, PLATFORM_ID_VMS = 700 } public void enumerateMachines ( ) { IntPtr buffer = new IntPtr(); int totalEntries = 0; int entriesRead = 0; int result; result = NetApi.NetServerEnum ( null, 100, out buffer, MAX_PREFERRED_LENGTH, ref entriesRead, ref totalEntries, (uint) ServerTypes.WorkStation, null, IntPtr.Zero ); MachineInfo machineInfo; if (result != FAIL) { Console.WriteLine ( "Succeeded!" ); Console.WriteLine ( entriesRead ); for (int i = 0; i < entriesRead; ++i) { machineInfo = (MachineInfo) Marshal.PtrToStructure ( buffer, typeof ( MachineInfo ) ); //machines.Add ( machineInfo ); Console.WriteLine ( machineInfo.serverName ); buffer = (IntPtr) ( (ulong) buffer + (ulong) Marshal.SizeOf ( machineInfo ) ); } NetApi.NetApiBufferFree ( buffer ); } } } }
C# Syntax (Toggle Plain Text)
namespace LanIpAddresses { class Program { private static IPHostEntry ipHost; static ArrayList ipList; static void Main ( string[ ] args ) { EnumerateLanMachines enumerate = new EnumerateLanMachines ( ); enumerate.enumerateMachines ( ); /*foreach (EnumerateLanMachines.MachineInfo o in enumerate.machines) { Console.WriteLine ( o.platformId + " " + o.serverName ); }*/ Console.ReadLine ( ); } } }
Bhoot
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
Other Threads in the C# Forum
- Previous Thread: Cannot implicitly convert type 'object' to 'char[]'.
- Next Thread: Drag and drop issue
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime datetimepicker degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





