Get All computer in the Network : WMI ?

  • Thread starter Thread starter jason
  • Start date Start date
J

jason

Hi all ,
I need a script that let my know all computer in my Network .

I have see that WMI allow me to query more and more
information on system .

But I haven't found anythink for get the List of all computer
in Network .

any help ?

Thanks ,
jason.
 
some code i found - can't remember where - www.codeproject.com probably

// server types accepted by the NetServerEnum function
public enum SV_101_TYPES:uint
{
SV_TYPE_WORKSTATION= 0x00000001,
SV_TYPE_SERVER= 0x00000002,
SV_TYPE_SQLSERVER = 0x00000004,
SV_TYPE_DOMAIN_CTRL= 0x00000008,
SV_TYPE_DOMAIN_BAKCTRL= 0x00000010,
SV_TYPE_TIME_SOURCE= 0x00000020,
SV_TYPE_AFP= 0x00000040,
SV_TYPE_NOVELL= 0x00000080,
SV_TYPE_DOMAIN_MEMBER = 0x00000100,
SV_TYPE_PRINTQ_SERVER = 0x00000200,
SV_TYPE_DIALIN_SERVER = 0x00000400,
SV_TYPE_XENIX_SERVER = 0x00000800,
SV_TYPE_SERVER_UNIX= SV_TYPE_XENIX_SERVER,
SV_TYPE_NT= 0x00001000,
SV_TYPE_WFW= 0x00002000,
SV_TYPE_SERVER_MFPN= 0x00004000,
SV_TYPE_SERVER_NT = 0x00008000,
SV_TYPE_POTENTIAL_BROWSER = 0x00010000,
SV_TYPE_BACKUP_BROWSER= 0x00020000,
SV_TYPE_MASTER_BROWSER= 0x00040000,
SV_TYPE_DOMAIN_MASTER = 0x00080000,
SV_TYPE_SERVER_OSF= 0x00100000,
SV_TYPE_SERVER_VMS= 0x00200000,
SV_TYPE_WINDOWS= 0x00400000, SV_TYPE_DFS= 0x00800000, SV_TYPE_CLUSTER_NT=
0x01000000,
SV_TYPE_TERMINALSERVER= 0x02000000, SV_TYPE_CLUSTER_VS_NT = 0x04000000,
SV_TYPE_DCE= 0x10000000,
SV_TYPE_ALTERNATE_XPORT= 0x20000000, SV_TYPE_LOCAL_LIST_ONLY= 0x40000000,
SV_TYPE_DOMAIN_ENUM= 0x80000000,
SV_TYPE_ALL= 0xFFFFFFFF
};

// Server info function, returned by the NetServerEnum function
[StructLayout(LayoutKind.Sequential)]
public struct SERVER_INFO_101
{
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]
public UInt32 sv101_platform_id;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string sv101_name;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] public
UInt32 sv101_version_major;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] public
UInt32 sv101_version_minor;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] public
UInt32 sv101_type;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] public
string sv101_comment;
};

public enum PLATFORM_ID
{
PLATFORM_ID_DOS = 300,
PLATFORM_ID_OS2 = 400,
PLATFORM_ID_NT = 500,
PLATFORM_ID_OSF = 600,
PLATFORM_ID_VMS = 700
}


// System functions imported
[DllImport("netapi32.dll",EntryPoint="NetServerEnum")]
public static extern int NetServerEnum(
[MarshalAs(UnmanagedType.LPWStr)]string servername,
int level, out IntPtr bufptr, int prefmaxlen, ref int entriesread, ref
int totalentries, SV_101_TYPES servertype,
[MarshalAs(UnmanagedType.LPWStr)]string domain, int resume_handle );

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

// if u need to send a text message to one of the found servers
[DllImport ("Netapi32", CharSet=CharSet.Unicode)]
public static extern int NetMessageBufferSend(
string servername,
string msgname,
string fromname,
string buf,
int buflen);

// example loads all available stations into a stationsTrv (a treeview on a
form)
stationsTrv.BeginUpdate();
stationsTrv.Nodes.Clear();
int entriesread = 0, totalentries = 0;

do
{
// Buffer to store the available servers
// Filled by the NetServerEnum function
IntPtr buf = new IntPtr();
// Server structure
SERVER_INFO_101 server;
// call NetServerEnum function. The '101' defines the type of
// structure returned, in this case, SERVER_INFO_101 which contains
// the type of information we need. In the preferred max length
parameter
// '-1' is passed to tell the function to allocate the necessary amount
of
// memory for the data. The SV_TYPE_WORKSTATION tells the function to
only
// return workstation type servers.
int ret = NetServerEnum(null,101,out buf,-1,
ref entriesread,ref totalentries,
SV_101_TYPES.SV_TYPE_WORKSTATION,null,0);

// if the function returned any data, fill the tree view
if( ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA || entriesread > 0 )
{
Int32 ptr = buf.ToInt32();
for(int i=0; i<entriesread; i++)
{
// cast the pointer to a SERVER_INFO_101 structure
server = (SERVER_INFO_101)Marshal.PtrToStructure(new
IntPtr(ptr),typeof(SERVER_INFO_101));
ptr += Marshal.SizeOf(server);
// add the workstation name to the tree view
stationsTrv.Nodes.Add( new
TreeNode(server.sv101_name.ToLower()) );
}
}
else
{
// no servers found
MessageBox.Show("No servers found in network");
}
// free the buffer
NetApiBufferFree(buf);
} while( entriesread < totalentries && entriesread != 0 );

stationsTrv.EndUpdate();


hope this is what u were looking for

;-)
 
Back
Top