WR Vishnu Coldfusion Weblog

Blog for Coldfusion and Coldfusion related technologies….

Getting System/OS information in Coldfusion

Posted by wrvishnu on October 5, 2007

This Article describe how to get the follwoing system information in Coldfusion using .Net OS Information

  • Hard Disk Information
  • IP and Computer Name
  • Mac Address
  • Computer information

Steps to follow

Create a Class Library in .Net and compile and get the dll file generated from .Net

Call the dll from coldfusion and access the methods from dll

.Net Code Snippets

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;
using System.Data;
using System.Net;
using System.Text;
using System.Management;
public class OSinformation
{
// Method to get the HardDisk Informationpublic DataTable GetDriveInfo()
{
ManagementObjectSearcher query1 = new ManagementObjectSearcher(”SELECT * FROM Win32_LogicalDisk”);
ManagementObjectCollection queryCollection1 = query1.Get();
DataTable DT = new DataTable();
// Add the Columns headers to the table
DT.Columns.Add(”DeviceID”);
DT.Columns.Add(”Description”);
DT.Columns.Add(”Freespace”);
foreach (ManagementObject mo in queryCollection1)
{
// Adding the rwos to the table
DataRow drdummy= DT.NewRow();
drdummy["DeviceID"] = mo["DeviceID"].ToString();
drdummy["Description"] = mo["Description"].ToString();
drdummy["Freespace"] = Convert.ToInt64(mo["Freespace"])/ 1024/1024 + ” MB”;
DT.Rows.Add(drdummy);
}
return DT;
}
// Method to get the OS Information
public DataTable GetOsinfo()
{
ManagementObjectSearcher query2 = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
ManagementObjectCollection queryCollection2 = query2.Get();
DataTable OSDT = new DataTable();
// Add the Columns headers to the table
OSDT.Columns.Add(”name”);
OSDT.Columns.Add(”version”);
OSDT.Columns.Add(”csname”);
OSDT.Columns.Add(”windowsdirectory”);
foreach (ManagementObject mo in queryCollection2)
{
DataRow drdummy = OSDT.NewRow();
drdummy["name"] = mo["name"].ToString();
drdummy["version"] = mo["version"].ToString();
drdummy["csname"] = mo["csname"].ToString();
drdummy["windowsdirectory"] = mo["windowsdirectory"].ToString();

OSDT.Rows.Add(drdummy);

}
return OSDT;
}

// Method to get the Computer Information
public DataTable GetCSinfo()
{
ManagementObjectSearcher query3 = new ManagementObjectSearcher(”SELECT * FROM Win32_ComputerSystem”);
ManagementObjectCollection queryCollection3 = query3.Get();
DataTable CSDT = new DataTable();
CSDT.Columns.Add(”manufacturer”);
CSDT.Columns.Add(”model”);
CSDT.Columns.Add(”systemtype”);
CSDT.Columns.Add(”Memory”);

foreach (ManagementObject mo in queryCollection3)
{

DataRow drdummy = CSDT.NewRow();
drdummy["manufacturer"] = mo["manufacturer"].ToString();
drdummy["model"] = mo["model"].ToString();
drdummy["systemtype"] = mo["systemtype"].ToString();
drdummy["Memory"] = mo["totalphysicalmemory"].ToString();

CSDT.Rows.Add(drdummy);

}
return CSDT;
}

public String GetIPAndCompName()
{
String S22;
String ComputerName;
String IP;
ComputerName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(ComputerName);
IP = ipEntry.AddressList[0].ToString();
S22 = IP + “,” + ComputerName;
return S22;
}
///
/// Returns MAC Address from first Network Card in Computer
///
/// [string] MAC Address
public string GetMACAddress()
{
ManagementClass mc = new ManagementClass(”Win32_NetworkAdapterConfiguration”);
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}
MACAddress = MACAddress.Replace(”:”, “”);
return MACAddress;
}

///
/// Return processorId from first CPU in machine
///
/// [string] ProcessorId
public string GetCPUId()
{
string cpuInfo = String.Empty;
string temp = String.Empty;
ManagementClass mc = new ManagementClass(”Win32_Processor”);
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{// only return cpuInfo from first CPU
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
return cpuInfo;
}

}

CFM Code

<cfobject
type = “dotnet”
name = “MDBDTable”
class = “OSinformation”
assembly =”d:/Vishnu/OSinformation.dll”>

<cfset dummy = MDBDTable.GetCSinfo()>
<cfdump var=”#dummy#”><br>

<cfset dummy = MDBDTable.GetDriveInfo()>
<cfdump var=”#dummy#”><br>

<cfset dummy = MDBDTable.GetOsinfo()>
<cfdump var=”#dummy#”><br>

<cfset dummy = MDBDTable.GetIPAndCompName()>
<cfset IP = listgetat(dummy,1)>
<cfset domain = listgetat(dummy,2)>
<cfoutput>
IP is #IP# <br>
Domain is #domain#<br>

<cfset dummy = MDBDTable.GetMACAddress()>
Macaddress is : #dummy#
</cfoutput>

Source fot this sample can be get from the url https://share.adobe.com/adc/document.do?docid=4298a1c1-7327-11dc-b75f-151d3f6d9313

4 Responses to “Getting System/OS information in Coldfusion”

  1. Brad Says:

    Is there a way throught the .net interface to call sharepoint?

  2. wrvishnu Says:

    Do u mean call sharepoint from .coldfusion?
    No UI component can be called using coldfusion and .Net integration

    call sharepoing from .Net itself?
    possible i guess

  3. Sam Farmer Says:

    WR,

    I get this error when running your code:

    Class OSinformation not found in the specified assembly list.

    Any idea what I am doing wrong?

    Thanks,

    Sam

  4. the graphic designer digital toolkit Says:

    HP Rolls Out Printers, Web

    HP Rolls Out Printers, Web Services For Businesses, ConsumersInformationWeek, NY -16 hours agocampaign, HP solicited the help of rock star/fashion designer Gwen

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>