Introduction
My app provides a mechanism for supplying a list of all PC names in the local network. It scans the software installed with their product keys in each machine from its registry and displays it against the Machine. It will also scans hardware details such as Make, Model, Clock Speed, Hard Disk size, RAM and all. This app is very useful for the infrastructure admins to monitor and maintain the list of sotware and its licenses along with the hardware details.
Background
This application is very good tool for the administrator to keep track of all the PC related information.Whenever user installs new software without giving information to admin,this app send a an alert mail to admin against the installed software.All installed and uninstalled software and any system upgradation details can be tracked.
This app makes use of the following code
-
[DllImport("Netapi32", CharSet = CharSet.Auto, SetLastError = true),
SuppressUnmanagedCodeSecurityAttribute]
public static extern int NetServerEnum(
string ServerNane,
int dwLevel,
ref IntPtr pBuf,
int dwPrefMaxLen,
out int dwEntriesRead,
out int dwTotalEntries,
int dwServerType,
string domain,
out int dwResumeHandle
);
-
[DllImport("Netapi32", SetLastError = true),
SuppressUnmanagedCodeSecurityAttribute]
public static extern int NetApiBufferFree(
IntPtr pBuf);
[StructLayout(LayoutKind.Sequential)]
public struct _SERVER_INFO_100
{
internal int sv100_platform_id;
[MarshalAs(UnmanagedType.LPWStr)]
internal string sv100_name;
}
-
ArrayList networkComputers = new ArrayList();
-
const int MAX_PREFERRED_LENGTH = -1;
int SV_TYPE_WORKSTATION = 1;
int SV_TYPE_SERVER = 2;
string strDmn = "domain";
IntPtr buffer = IntPtr.Zero;
IntPtr tmpBuffer = IntPtr.Zero;
int entriesRead = 0;
int totalEntries = 0;
int resHandle = 0;
int sizeofINFO = Marshal.SizeOf(typeof(_SERVER_INFO_100));
try
{
int ret = NetServerEnum(null, 100, ref buffer, MAX_PREFERRED_LENGTH,
out entriesRead,
out totalEntries,SV_TYPE_WORKSTATION | SV_TYPE_SERVER , null, out
resHandle);
if (ret == 0)
{
for (int i = 0; i < totalEntries; i++)
{
tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));
_SERVER_INFO_100 svrInfo = (_SERVER_INFO_100)
Marshal.PtrToStructure(tmpBuffer, typeof(_SERVER_INFO_100));
networkComputers.Add(svrInfo.sv100_name);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Problem with acessing network computers in NetworkBrowser " +
"\r\n\r\n\r\n" + ex.Message,
"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return null;
}
finally
{
NetApiBufferFree(buffer);
}
-
By using the above code we got the List of PCs connected in local Network.
6. Gets all the PC names into an Arraylist and for each PC perform the following tasks
- Ping the PC using ping object
- if ping status is success then connect to registry of the system and go through the Registry Keys to get the information required.
- Get the software information such as Display Name,Install location,Install date,Publisher and any License key
- Get the Hardware details from win32 classes
Points of Interest
I learned many things about Registry information and also Win32 system classes while developing this app.
History
This is the version 1.0 of my app.