WR Vishnu Coldfusion Weblog

Blog for Coldfusion and Coldfusion related technologies….

Archive for October, 2007

Suggest Coldfusion .Net integration

Posted by wrvishnu on October 18, 2007

Hi All

I would like you to suggest some samples that you required  using  Coldfusion and .Net integration.

Accessing the .Net UI controls  will not be accessible in Coldfusion any example using .Net ui cannot be done in coldfusion

Why wait post you suggestion in comment section….

Posted in Coldfusion | 15 Comments »

Downlaod EventViewer Log and Save in Database

Posted by wrvishnu on October 6, 2007

This Article describe how to get the event viewer log and clear the data from .Net and Save the event viewer into database in Coldfusion

To do this we need to create a class in .Net which will get the event viewer log and clear the entry and return the data as datatable which can be used from coldfusion and save the same in databasse

Create the table using the query below

CREATE TABLE EVENTVIEWERDATA ( EVENTID INTEGER, ENTRYTYPE VARCHAR2 (200), MESSAGE VARCHAR2 (4000),TIME VARCHAR2 (800))

.Net Code


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;
public class EvtViewerSample
{
public DataTable getEventviewer(String EventLogName)
{
// Create the object for EventLog
EventLog ev = new EventLog(EventLogName, System.Environment.MachineName, "MyAppName");

//Create the columns for the datatable
DataTable CSDT = new DataTable();
CSDT.Columns.Add("EventId");
CSDT.Columns.Add("Message");
CSDT.Columns.Add("EntryType");
CSDT.Columns.Add("Time");

try
{

// Loop through the data and add a row
foreach (EventLogEntry entry in ev.Entries)
{

DataRow drdummy = CSDT.NewRow();
drdummy["EventId"] = entry.InstanceId.ToString();
drdummy["Message"] = entry.Message.ToString();
drdummy["EntryType"] = entry.EntryType.ToString();
drdummy["Time"] = entry.TimeGenerated.ToString();
CSDT.Rows.Add(drdummy);

}
ev.Clear(); // Clear the log information
ev.Close(); // Close the connection

return CSDT;
}
catch (Exception ex)
{
throw ex;
}

}

}

CFM Code
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Eventviewer Demo</title>
</head>
<body> <!—CAll the .Net method by passing the event log name like Application or Security or SystemNote : Current code will clear the Log file from event Viewer Please dont try this in Production database

—->

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

<cftry>

<strong>Note: All Event log entried are cleared and saved in the database </strong>
<cfset Qrydata = #EvtDemo.getEventviewer(“Security”)#>
<cfloop query=”Qrydata”>
<cfquery name=”InsData” datasource=”CWtestsrv”>
Insert into EVENTVIEWERDATA (EVENTID, ENTRYTYPE,MESSAGE,TIME)
Values (
‘#Qrydata.EVENTID#’,
‘#Qrydata.ENTRYTYPE#’,
‘#Qrydata.MESSAGE#’,
‘#Qrydata.TIME#’)
</cfquery>
</cfloop>

<cfdump var=”#Qrydata#”>

<cfcatch type=”Any” >

<h3>Error Occured</b></h3>
<cfoutput>
<!— and the diagnostic message from the ColdFusion server —>
<p>#cfcatch.message#</p>
<p>Caught an exception, type = #CFCATCH.TYPE# </p>
<p>The contents of the tag stack are:</p>
<cfloop index = i from = 1
to = #ArrayLen(CFCATCH.TAGCONTEXT)#>
<cfset sCurrent = #CFCATCH.TAGCONTEXT[i]#>
<br>#i# #sCurrent["ID"]#
(#sCurrent["LINE"]#,#sCurrent["COLUMN"]#)
#sCurrent["TEMPLATE"]#
</cfloop>
</cfoutput>
</cfcatch>
</cftry>

Code Samples avilable  in the link

https://share.adobe.com/adc/document.do?docid=91bcf306-7405-11dc-b75f-151d3f6d9313

Posted in Coldfusion | 3 Comments »

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

Posted in Coldfusion, Coldfusion Blogs | 4 Comments »