Welcome to CodeGlobe. CodeGlobe provides free source code, tutorials and latest useful technology news.
Wednesday, September 30, 2009
Wednesday, September 23, 2009
Lost Task Manager? alternate solution!
It is often happens the very annoying alert message in the windows operating system, "Task manager has been disabled by the administrator!" really??. This is because of some malicious program being run in the back ground and it is normally invisible to the user. The only easy way to monitor this simply the task manager! right?. Task manager is a graphic tool used to monitor the current running process and applications and related details of these.
it is happy to know that the malicious program writers or the virus writers are really scare with this Task manager. A experienced administrator can easily find out
with the help of this task manager what are the suspected programs running in the background other than the normal programs. consequently their program process could be stopped by the administrator. In order to prevent this these ugly guys often programmed into disable the task manager.
Task manager can be re enabled in a file using "gpedit.msc" in the administrative templates that is there.But the "ugly" writers are more than of that when we re enable the task manager, within seconds or less than of second they will disappear it again.This means the malicious program still running in the background and must be stopped right?
Here is the solution...
netstat command could be used for alternative of to identify what are the program running in the background according to their name,memory usage and process ID.
here is a brief description of netstat with very useful options.
netstat -anbo
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection
-a Displays all connections and listening ports
-b Displays the executable involved in creating each connection or
listening port.
the above command in the cmd will result a detailed status of the program with name, process id, including the dll fles etc.
simply use the process id to input to the "tskill" command.
ex.
tskill 8299
where 8299 will be the process id of suspected process.And this is one of the ways you can achieve this task right?.
regards..
it is happy to know that the malicious program writers or the virus writers are really scare with this Task manager. A experienced administrator can easily find out
with the help of this task manager what are the suspected programs running in the background other than the normal programs. consequently their program process could be stopped by the administrator. In order to prevent this these ugly guys often programmed into disable the task manager.
Task manager can be re enabled in a file using "gpedit.msc" in the administrative templates that is there.But the "ugly" writers are more than of that when we re enable the task manager, within seconds or less than of second they will disappear it again.This means the malicious program still running in the background and must be stopped right?
Here is the solution...
netstat command could be used for alternative of to identify what are the program running in the background according to their name,memory usage and process ID.
here is a brief description of netstat with very useful options.
netstat -anbo
-n Displays addresses and port numbers in numerical form.
-o Displays the owning process ID associated with each connection
-a Displays all connections and listening ports
-b Displays the executable involved in creating each connection or
listening port.
the above command in the cmd will result a detailed status of the program with name, process id, including the dll fles etc.
simply use the process id to input to the "tskill" command.
ex.
tskill 8299
where 8299 will be the process id of suspected process.And this is one of the ways you can achieve this task right?.
regards..
Sunday, September 20, 2009
Struts2 align check box vertical
Normally the struts checkboxlist in struts2 diaply the check boxes horizontally. In most of application we want to
display the check boxes vetrically ie line by line. For aligning this as vertical we have to do as specified below
1) You have to create a directory template in your src folder
2) create a folder with name of the template you want to create (vertical-checkbox)
3) copy the struts-2.1.6/src/core/src/main/resources/template/simple/checkboxlist.ftl file to this directory content of this file is as follows. Before the </@s.iterator> you have to put a <br> tag as I given in this
<#--
/*
* $Id: checkboxlist.ftl 720258 2008-11-24 19:05:16Z musachy $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<#assign itemCount = 0/>
<#if parameters.list??>
<@s.iterator value="parameters.list">
<#assign itemCount = itemCount + 1/>
<#if parameters.listKey??>
<#assign itemKey = stack.findValue(parameters.listKey)/>
<#else>
<#assign itemKey = stack.findValue('top')/>
</#if>
<#if parameters.listValue??>
<#assign itemValue = stack.findString(parameters.listValue)?default("")/>
<#else>
<#assign itemValue = stack.findString('top')/>
</#if>
<#assign itemKeyStr=itemKey.toString() />
<input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>
</#if>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
<#if parameters.title??>
title="${parameters.title?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
<label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>
<br>
</@s.iterator>
<#else>
</#if>
4) <s:checkboxlist list="urlist" name="selectedValues" listKey="id" listValue="descrption" theme="vertical-checkbox"></s:checkboxlist>
this will give you vertical check box list
only difference is that here you have to specify the theme which is same as the directory u have created in the template directory in the src folder of your project
display the check boxes vetrically ie line by line. For aligning this as vertical we have to do as specified below
1) You have to create a directory template in your src folder
2) create a folder with name of the template you want to create (vertical-checkbox)
3) copy the struts-2.1.6/src/core/src/main/resources/template/simple/checkboxlist.ftl file to this directory content of this file is as follows. Before the </@s.iterator> you have to put a <br> tag as I given in this
<#--
/*
* $Id: checkboxlist.ftl 720258 2008-11-24 19:05:16Z musachy $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<#assign itemCount = 0/>
<#if parameters.list??>
<@s.iterator value="parameters.list">
<#assign itemCount = itemCount + 1/>
<#if parameters.listKey??>
<#assign itemKey = stack.findValue(parameters.listKey)/>
<#else>
<#assign itemKey = stack.findValue('top')/>
</#if>
<#if parameters.listValue??>
<#assign itemValue = stack.findString(parameters.listValue)?default("")/>
<#else>
<#assign itemValue = stack.findString('top')/>
</#if>
<#assign itemKeyStr=itemKey.toString() />
<input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>
</#if>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
<#if parameters.title??>
title="${parameters.title?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
<label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>
<br>
</@s.iterator>
<#else>
</#if>
4) <s:checkboxlist list="urlist" name="selectedValues" listKey="id" listValue="descrption" theme="vertical-checkbox"></s:checkboxlist>
this will give you vertical check box list
only difference is that here you have to specify the theme which is same as the directory u have created in the template directory in the src folder of your project
Monday, September 14, 2009
Send Email from Java program using apache commons email
This api allows you to send email from your java progra. You can download the API from the folowing site
Download
Here I am giving you a sample code which lets you to send email fromyuor system
SimpleEmail email = new SimpleEmail();
email.setHostName("localhost");
try {
email.addTo("nimishth@gmail.com","Nimish T");
email.setFrom("admin@localhost");
email.setSubject("test");
email.setMsg("test message");
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
first of all you have to include the downloaded library into u'r class path
after that write a java class and create an instarnce of SimpleEmail
then you have to set the set the host name, from address and to address
after that just add the message you want to send and and set a subject for the
perticular instance of the SimpleEmail class. here after you can call the sen method
which will send the email to the to address you have specified here its nimishth@gmail.com
If u want to send the mail using oter hservice providers such as gmail or oters
u have to change the the host name by the smtp address of the service provider you want to use
but there need authentication also
ie
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
try {
email.addTo("nimishth@gmail.com","Nimish T");
email.setFrom("your email address");
email.setAuthentication("yoru email address", "your password");
email.setTLS(true);
//465 or 587 which is the port number here
email.setSmtpPort(587);
email.setSubject("Test");
email.setMsg("test");
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
You will get more details about the mail such as attachment, html mail etc from
User Guide
Download
Here I am giving you a sample code which lets you to send email fromyuor system
SimpleEmail email = new SimpleEmail();
email.setHostName("localhost");
try {
email.addTo("nimishth@gmail.com","Nimish T");
email.setFrom("admin@localhost");
email.setSubject("test");
email.setMsg("test message");
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
first of all you have to include the downloaded library into u'r class path
after that write a java class and create an instarnce of SimpleEmail
then you have to set the set the host name, from address and to address
after that just add the message you want to send and and set a subject for the
perticular instance of the SimpleEmail class. here after you can call the sen method
which will send the email to the to address you have specified here its nimishth@gmail.com
If u want to send the mail using oter hservice providers such as gmail or oters
u have to change the the host name by the smtp address of the service provider you want to use
but there need authentication also
ie
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
try {
email.addTo("nimishth@gmail.com","Nimish T");
email.setFrom("your email address");
email.setAuthentication("yoru email address", "your password");
email.setTLS(true);
//465 or 587 which is the port number here
email.setSmtpPort(587);
email.setSubject("Test");
email.setMsg("test");
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
You will get more details about the mail such as attachment, html mail etc from
User Guide
Saturday, September 12, 2009
Retrieving Query Result in a Tree Structure in MS SQL SERVER using Common Table Expression (CTE)
A common table expression or "CTE" is a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table. A derived table exists only for the duration of the query and is not stored as an object. But the problem with derived tables is the lack of self referencing. Here is where the importance of CTE comes in. A CTE can be self-referencing and it can be referenced multiple times in a query. Here we discuss about the recursive nature of CTE i.e to create a recursive query. Returning hierarchical data is a common use of recursive queries i.e for example suppose we want to create a general ledger(Example query is given at the end of this section). For now lets have a look at the recursive CTE. The following are the components of a recursive CTE:
WITH cte_name [(col1,col2,......,coln)] (Here the column names are optional)
AS
(
cte_query (Anchor member defined here)
UNION ALL
cte_query(recursive member referencing cte_name here)
)
select statement to retrieve the result
A recursive CTE consists of three elements:
1). Invocation of the routine
This part consist of one or more cte_query definitions joined by UNION ALL, UNION, EXCEPT, or INTERSECT operators. This query definitions are referred to as anchor elements because they form the base resultset of CTE.
2)Recursive invocation of routine
The recursive invocation includes one or more CTE_query_definitions joined by UNION ALL operators that reference the CTE itself. These query definitions are referred to as recursive members.
3)Termination check.
The termination check is implicit i.e recursion stops when no rows are returned from the previous invocation.
The semantics behind CTE is as follows:
a)Splitting the CTE expression into anchor and recursive members.
b) Then we run the anchor member creating the first invocation or base result, say BR0 .
c) Now we run the recursive member with BRi(where i=0 to n) as input and BRi+1 as output.
d) Repeat step c until an empty set is returned.
e)Return the resultset this is BR0 UNION ALL BRn
Example Query
WITH MyLedger(BranchID, AccParentID, AccID) AS
(
SELECT DISTINCT BranchID,AccParentID, AccID
FROM GeneralLedger
WHERE ActiveFlag='Y'
UNION ALL
SELECT e.BranchID,e.AccParentID, e.AccID
FROM GeneralLedger e
INNER JOIN MyLedger d
ON e.AccParentID = d.AccID AND E.BranchID=d.BranchID AND ActiveFlag='Y'
)
SELECT * FROM MyLedger
BranchID-denotes the branch.
AccParentID- denotes the parent group here.
AccID-denotes the account id.
The above result displays a General Ledger in a Tree Structure branch wise. Here we form our base result from the table GeneralLedger.
Happy Programming...... Enjoy!!!!!!!!!!!!!!!!!!!!!!!!!
WITH cte_name [(col1,col2,......,coln)] (Here the column names are optional)
AS
(
cte_query (Anchor member defined here)
UNION ALL
cte_query(recursive member referencing cte_name here)
)
select statement to retrieve the result
A recursive CTE consists of three elements:
1). Invocation of the routine
This part consist of one or more cte_query definitions joined by UNION ALL, UNION, EXCEPT, or INTERSECT operators. This query definitions are referred to as anchor elements because they form the base resultset of CTE.
2)Recursive invocation of routine
The recursive invocation includes one or more CTE_query_definitions joined by UNION ALL operators that reference the CTE itself. These query definitions are referred to as recursive members.
3)Termination check.
The termination check is implicit i.e recursion stops when no rows are returned from the previous invocation.
The semantics behind CTE is as follows:
a)Splitting the CTE expression into anchor and recursive members.
b) Then we run the anchor member creating the first invocation or base result, say BR0 .
c) Now we run the recursive member with BRi(where i=0 to n) as input and BRi+1 as output.
d) Repeat step c until an empty set is returned.
e)Return the resultset this is BR0 UNION ALL BRn
Example Query
WITH MyLedger(BranchID, AccParentID, AccID) AS
(
SELECT DISTINCT BranchID,AccParentID, AccID
FROM GeneralLedger
WHERE ActiveFlag='Y'
UNION ALL
SELECT e.BranchID,e.AccParentID, e.AccID
FROM GeneralLedger e
INNER JOIN MyLedger d
ON e.AccParentID = d.AccID AND E.BranchID=d.BranchID AND ActiveFlag='Y'
)
SELECT * FROM MyLedger
BranchID-denotes the branch.
AccParentID- denotes the parent group here.
AccID-denotes the account id.
The above result displays a General Ledger in a Tree Structure branch wise. Here we form our base result from the table GeneralLedger.
Happy Programming...... Enjoy!!!!!!!!!!!!!!!!!!!!!!!!!
Retrieve Query result(records) as Comma Separated Value in SQL Server
Its been a while that i've posted an article here. This time i am sharing a technique by which you can retrieve result from MS SQL Server in the form of Comma Separated Values(CSV). The idea is to display all the states from a particular country in CSV format.For this purpose we first create a table and name it "Country". Then we create two fields in the table, one for holding the country name and the second for holding the state name, say "countryname" and "state" respectively. After Creating the above table copy and paste the below code in your SQL Query Analyzer and Run it. Now you can see the magic!!. What is the idea behind this query?. Lets examine it.
DECLARE @s varchar(3500)
SET @s=''
SELECT @s=state +','+@s FROM Country WHERE countryname='INDIA'
SELECT @S
The keyword DECLARE is used to declare a variable named s and declare its datatype as varchar which can hold upto 3500 chars. Then we use the SET keyword to null string because if we dont assign it to null string the result will also be null. Now we use SELECT keyword to assign the result set into @s. Then at last we print our result using the last SELECT Keyword.
I know what i presented here is not a "Big thing", But every one knows nothing is so simple ever..........................
DECLARE @s varchar(3500)
SET @s=''
SELECT @s=state +','+@s FROM Country WHERE countryname='INDIA'
SELECT @S
The keyword DECLARE is used to declare a variable named s and declare its datatype as varchar which can hold upto 3500 chars. Then we use the SET keyword to null string because if we dont assign it to null string the result will also be null. Now we use SELECT keyword to assign the result set into @s. Then at last we print our result using the last SELECT Keyword.
I know what i presented here is not a "Big thing", But every one knows nothing is so simple ever..........................
Subscribe to:
Posts (Atom)