Monday, December 29, 2008
How to find the number of feilds in a table
where table_name = 'table_name'
Monday, December 22, 2008
Visual Studio .NET 2003 Keyboard Shortcuts
Tuesday, December 16, 2008
More date formats that does not come standard in SQL Server as part of the CONVERT function
SQL Statement | Sample Output |
SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 8) AS [YY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(8), GETDATE(), 11), '/', '-') AS [YY-MM-DD] | 99-01-24 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 111), '/', '-') AS [YYYY-MM-DD] | 1999-01-24 |
SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 3), 5) AS [MM/YY] SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 3), 4, 5) AS [MM/YY] | 08/99 |
SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 103), 7) AS [MM/YYYY] | 12/2005 |
SELECT CONVERT(VARCHAR(5), GETDATE(), 11) AS [YY/MM] | 99/08 |
SELECT CONVERT(VARCHAR(7), GETDATE(), 111) AS [YYYY/MM] | 2005/12 |
SELECT DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY] | July 04, 2006 1 |
SELECT SUBSTRING(CONVERT(VARCHAR(11), GETDATE(), 113), 4, 8) AS [Mon YYYY] | Apr 2006 1 |
SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS [Month YYYY] | February 2006 1 |
SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) AS [DD Month] | 11 September 1 |
SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR(2)) AS [Month DD] | September 11 1 |
SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) + ' ' + RIGHT(CAST(YEAR(GETDATE()) AS VARCHAR(4)), 2) AS [DD Month YY] | 19 February 72 1 |
SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS [DD Month YYYY] | 11 September 2002 1 |
SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 5), 5) AS [MM-YY] SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 5), 4, 5) AS [MM-YY] | 12/92 |
SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 105), 7) AS [MM-YYYY] | 05-2006 |
SELECT RIGHT(CONVERT(VARCHAR(7), GETDATE(), 120), 5) AS [YY-MM] SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 5) AS [YY-MM] | 92/12 |
SELECT CONVERT(VARCHAR(7), GETDATE(), 120) AS [YYYY-MM] | 2006-05 |
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '') AS [MMDDYY] | 122506 |
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY] | 12252006 |
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 3), '/', '') AS [DDMMYY] | 240702 |
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 103), '/', '') AS [DDMMYYYY] | 24072002 |
SELECT REPLACE(RIGHT(CONVERT(VARCHAR(9), GETDATE(), 6), 6), ' ', '-') AS [Mon-YY] | Sep-02 1 |
SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11), GETDATE(), 106), 8), ' ', '-') AS [Mon-YYYY] | Sep-2002 1 |
SELECT REPLACE(CONVERT(VARCHAR(9), GETDATE(), 6), ' ', '-') AS [DD-Mon-YY] | 25-Dec-05 1 |
SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') AS [DD-Mon-YYYY] | 25-Dec-2005 1 |
SQL Server Date Formats
SQL Statement | Sample Output |
SELECT CONVERT(VARCHAR(20), GETDATE(), 100) | Jan 1 2005 1:29PM 1 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY] | 11/23/98 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY] | 11/23/1998 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD] | 72.01.01 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD] | 1972.01.01 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY] | 19/02/72 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] | 19/02/1972 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY] | 25.12.05 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY] | 25.12.2005 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 5) AS [DD-MM-YY] | 24-01-98 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [DD-MM-YYYY] | 24-01-1998 |
SELECT CONVERT(VARCHAR(9), GETDATE(), 6) AS [DD MON YY] | 04 Jul 06 1 |
SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY] | 04 Jul 2006 1 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 7) AS [Mon DD, YY] | Jan 24, 98 1 |
SELECT CONVERT(VARCHAR(12), GETDATE(), 107) AS [Mon DD, YYYY] | Jan 24, 1998 1 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 108) | 03:24:53 |
SELECT CONVERT(VARCHAR(26), GETDATE(), 109) | Apr 28 2006 12:32:29:253PM 1 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 10) AS [MM-DD-YY] | 01-01-06 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY] | 01-01-2006 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 11) AS [YY/MM/DD] | 98/11/23 |
SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD] | 1998/11/23 |
SELECT CONVERT(VARCHAR(6), GETDATE(), 12) AS [YYMMDD] | 980124 |
SELECT CONVERT(VARCHAR(8), GETDATE(), 112) AS [YYYYMMDD] | 19980124 |
SELECT CONVERT(VARCHAR(24), GETDATE(), 113) | 28 Apr 2006 00:34:55:190 1 |
SELECT CONVERT(VARCHAR(12), GETDATE(), 114) AS [HH:MI:SS:MMM(24H)] | 11:34:23:013 |
SELECT CONVERT(VARCHAR(19), GETDATE(), 120) | 1972-01-01 13:42:24 |
SELECT CONVERT(VARCHAR(23), GETDATE(), 121) | 1972-02-19 06:35:24.489 |
SELECT CONVERT(VARCHAR(23), GETDATE(), 126) | 1998-11-23T11:25:43:250 |
SELECT CONVERT(VARCHAR(26), GETDATE(), 130) | 28 Apr 2006 12:39:32:429AM 1 |
SELECT CONVERT(VARCHAR(25), GETDATE(), 131) | 28/04/2006 12:39:32:429AM |
Sunday, December 14, 2008
Thursday, December 11, 2008
Check for an Integer Value-Without Exception
int number;
isvalid = int.TryParse(textBox1.Text,out number);
if (isvalid)
{
MessageBox.Show("Number");
}
if (isvalid == false)
{
MessageBox.Show("Not a number");
}
Monday, December 8, 2008
How to get configuraion Settings
using System.Collections.Specialized;
using System.Collections;
using System.Configuration;
NameValueCollection appSettings = ConfigurationManager.AppSettings;
string userName = appSettings["UserName"].ToString();
RUN a SP
con.Open();
SqlCommand cmd=new SqlCommand("SPNAME",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@SPPARAM", PARAM));
cmd.CommandTimeout=0;
SqlTransaction t=con.BeginTransaction();
cmd.Transaction=t;
try
{
cmd.ExecuteNonQuery();
t.Commit();
con.Close();
}
catch(Exception ex)
{
t.Rollback();
con.Close();
string s = ex.Message;
}
Creating a transaction
con.Open();
SqlCommand cmd=new SqlCommand(sql,con);
cmd.CommandTimeout=0;
SqlTransaction t=con.BeginTransaction();
cmd.Transaction=t;
try
{
SqlDataAdapter adpt=new SqlDataAdapter(cmd);
adpt.Fill(dsTemp);
t.Commit();
con.Close();
return ds;
}
catch(Exception ex)
{
t.Rollback();
con.Close();
return new DataSet();
}
Monday, October 20, 2008
Nested Case sql
WHEN(Status = 'Goods Issued')
OR (Status = 'Partially Issued')
THEN IssuedQty
ELSE '0' END)
AS QTYISSUED
How to get length of data in Text, NText and Image columns in SQL Server
Problem
There is sometimes a need to figure out the maximum space that is being used by a particular column in your database. You would initially think that the LEN() function would allow you to do this, but this function does not work on Text, NText or Image data types, so how do you figure out the length of a value in a column that has one of these data types?
Solution
In addition to the LEN() function, SQL Server also has a DATALENGTH() function. This function can be used on all data types in your table.
Here is an example of running these commands on an IMAGE data type using the LEN function:
SELECT name, LEN(packagedata)
FROM dbo.sysdtspackages
query results
Here is an example of running these commands on an IMAGE data type using the DATALENGTH function:
SELECT name, DATALENGTH(packagedata)
FROM dbo.sysdtspackages
query results
If you wanted to find out the maximum length used for all of your records you could issue a command such as the following:
SELECT TOP 1 name, DATALENGTH(packagedata)
FROM dbo.sysdtspackages
ORDER BY 2 DESC
That is all there is to it. Another little function that you probably won't use often, but this is helpful to know it is there when you do need to use it.
Monday, May 12, 2008
Working with Timer Control in C#
The Timer control allows you to set a time interval to execute an event after that interval continuously. It is useful when you want to execute certain applications after a certain interval. Say you want to create a backup of your data processing in every hour. You can make a routine which will take the backup and call that routine on Timer's event and set timer interval for an hour.
Using timer control is pretty simple. To test the control, I'm going to create a Windows Application. I also add two button controls to the form and change their text to Start and Stop as you can see from the following Figure.
In this application, I'm going to create a text file mcb.txt in your C:\temp directory and start writing the time after 5 seconds interval. Stop button stops the timer and Start again start the timer.
Now you can drag a timer control from the toolbox to the form. You can set timer properties from the IDE as well as programmatically. To set the timer properties, right click on the timer control and change Interval property. As you can see from the Figure,
I put 5000 milliseconds (5 seconds).
I sec = 1000 milliseconds (In case your mathematics is poor as mine ;).
Now click on the Events button and write event for the timer click as you can see from the following figure.
Now I add a FileStream and a StreamWriter object in the beginning of the class. As you can see from the following code, FileStream class creates a mcb.txt file and StreamWriter will be used to write to the file.
private static FileStream fs = new FileStream(@"c:\temp\mcb.txt", FileMode.OpenOrCreate, FileAccess.Write);
private static StreamWriter m_streamWriter = new StreamWriter(fs);
Now write the following code on the Form Load event:
private void Form1_Load(object sender, System.EventArgs e)
{
// Write to the file using StreamWriter class
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.Write(" File Write Operation Starts : ");
m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());
m_streamWriter.WriteLine(" ===================================== \n");
m_streamWriter.Flush();
}
As you can see from the above code, this code writes some lines to the file.
Now write code on the start and stop button click handlers. As you can see from the following code, the Start button click sets timer's Enabled property as true. Setting timer's Enabled property starts timer to execute the timer event. I set Enabled property as false on the Stop button click event handler, which stops executing the timer tick event.
private void button1_Click(object sender, System.EventArgs e)
{
timer1.Enabled = true;
}
private void button2_Click(object sender, System.EventArgs e)
{
timer1.Enabled = false;
}
Now last step is to write timer's tick event to write current time to the text file. Write the following code on your timer event.
private void timer1_Tick(object sender, System.EventArgs e)
{
m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());
m_streamWriter.Flush();
}
Now use Start and Stop buttons to start and stop the timer. The output mcb.txt file looks like the following figure.
Using Timer control Programmatically
If you don't have Visual Studio .NET, you can also write the same sample. Just following these steps.
Creating an instance of Timer
The Timer class's constructor is used to create a timer object. The constructor is overloaded.
Public Timer()
Public Timer(double) Sets the interval property to the specified.
Here is how to create a Timer with 5 seconds interval.
Timer myTimer = new Timer(500);
Here are some useful members of the Timer class:
Tick | This event occurs when the Interval has elapsed. |
Start | Starts raising the Tick event by setting Enabled to true. |
Stop | Stops raising the Tick event by setting Enabled to false. |
Close | Releases the resources used by the Timer. |
AutoReset | Indicates whether the Timer raises the Tick event each time the specified Interval has elapsed or whether the Tick event is raised only once after the first interval has elapsed. |
Interval | Indicates the interval on which to raise the Tick event. |
Enabled | Indicates whether the Timer raises the Tick event. |
timer1.Interval = 5000;
timer1.Enabled = true;
timer1.Tick += new System.EventHandler (OnTimerEvent);
Write the event handler
This event will be executed after every 5 secs.
public static void OnTimerEvent(object source, EventArgs e)
{
m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());
m_streamWriter.Flush();
}
This is originally posted by Mahesh Chand I used this for one of my projects.Hope this will help you all!!!!!
Creating a Windows Service in C#
NOTE: The project name in this sample code is mcWebService which is a spelling mistake. I meant to put mcWinService. And now I don't want to change all the screen shots and code all over again. I hope it won't confuse you :).
Ok, its time for one more tutorial. This times pick is Windows Services. Creating Windows Services is not a big deal using C# and Visual Studio. Just follow few simple steps and you are all set to run and test your first Windows Service.
Windows Services is new name for NT Services you used to develop in previous versions of Visual Studio. This tutorial walks you through how to create and use your Windows Services. This Service writes some text to a text file when stop and start the service. The base idea is taken from MSDN but its more elaborated. You can modify it according to your needs.
Step 1. Create Skeleton of the Service
To create a new Window Service, pick Windows Service option from your Visual C# Projects, give your service a name, and click OK.
The result look like this. The Wizard adds WebService1.cs class to your project.
Set your ServiceName to your own name so it would be easier to recognize your service during testing OR you can set this property programmatically using this line this.ServiceName = "mcWinService";
This is the name you will be looking for later :).
The default code of WebService1.cs added by the Wizard looks like here
namespace mcWebService
{
using System;
using System.Collections;
using System.Core;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Web.Services;
using System.Diagnostics;
using System.ServiceProcess;
public class WinService1 : System.ServiceProcess.ServiceBase
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components;
public WinService1()
{
// This call is required by the WinForms Component Designer. InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
/ create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new WinService1(), new
ySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WinService1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "WinService1";
}
///
/// Set things in motion so your service can do its work.
///
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
}
///
/// Stop this service.
///
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
}
}
Step 2. Add functionality to your service
As you saw WebService1.cs, there are two overridden functions OnStart and OnStop. The OnStart function executes when you start your service and the OnStop function gets execute when you stop a service. I write some text to a text file when you start and stop the service.
protected override void OnStart(string[] args)
{
FileStream fs = new FileStream(@"c:\temp\mcWindowsService.txt" ,
FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(" mcWindowsService: Service Started \n");
m_streamWriter.Flush();
m_streamWriter.Close();
}
///
/// Stop this service.
///
protected override void OnStop()
{
FileStream fs = new FileStream(@"c:\temp\mcWindowsService.txt" ,
FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(" mcWindowsService: Service Stopped \n"); m_streamWriter.Flush();
m_streamWriter.Close();
}
Step 3: Install and Run the Service
Build of this application makes one exe, mcWinService.exe. You need to call installutil to
egister this service from command line.
installutil C:\mcWebService\bin\Debug\mcWebService.exe
You use /u option to uninstall the service.
installutil /u C:\mcWebService\bin\Debug\mcWebService.exe
Run the application
Step 4: Start and Stop the Service
You need to go to the Computer Management to Start to start and stop the service. You can use Manage menu item by right clicking on My Computer.
Under Services and Applications, you will see the service mcWinService. Start and Stop menu item starts and stops the service.
Step 5: Test the Service
Go to your temp directory and see if text file is there with contents or not.
That's it.
This is originally posted by Mahesh Chand I used this for one of my projects hope this will be use full for you all!!!
Wednesday, March 5, 2008
Hidden Skype Emoticons, Smileys(Sri Lankan Flag)
Wanna Show Sri Lankan Flag when you are chatting. Here what you have to do .Type (flag:lk) Thats it.
Hidden Skype Emoticons, Smileys
Did you know that Skype have hidden emoticons? No! Below is a list of the all hidden emoticons that I know and use chatting with my friends.
How to use hidden emoticons? Actually it is pretty simple - you just need to enter the smiley code while chatting with your friends - for example type ‘(drunk)’ to display smiley who have had couple beers :)
Icon | Name | Type |
Mooning | (mooning) | |
Finger | (finger) | |
Bandit | (bandit) | |
Drunk | (drunk) | |
Smoking | (smoking)(smoke)(ci) | |
Toivo | (toivo) | |
Rock | (rock) | |
Headbang | (headbang)(banghead) | |
Bug | (bug) | |
Fubar | (fubar) | |
Poolparty | (poolparty) | |
Swearing | (swear) | |
TMI | (tmi) | |
Heidy | (heidy) | |
MySpace (Skype v3.6) | (myspace) |
Skype emoticons (bandit) (drunk) (finger) (headbang) (banghead) (mooning) (rock) (smoking) (smoke) (ci) (toivo) work with Skype 2.5 and 3.0!
Smileys (bug) (fubar) (poolparty) (swear) (tmi) work only with Skype 3.0 and up!How to Get "Show Hidden Files and Folders" Back if it is Missing(Edit Registry Another Fix)
and export the whole thing.)
find this key: HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Explorer\Advanced. Go to the rightside of the window,
where the values are. Find the value "Hidden" . Rightclick it and modify it to 1.
How to Get "Show Hidden Files and Folders" Back if it is Missing
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
\CurrentVersion\Explorer\Advanced\Folder\Hidden]
Modify the string value "Type" and enter "group" as value data.
After the edit is complete hit F5 to refresh, and go look in your Folder Options.
Wednesday, February 27, 2008
USB Drive AutoRun.inf Tweaking
Autorun.inf Structure
The autorun.inf file is a simple text file that can be opened up in any text editor (e.g. notepad). It always starts with a section header of:
[autorun]
Below this header is a list of different options. Each of these options is in the following format:
option=value
where
option
is the option that you want to set and value
is the value that you are setting for that option. So, if you had an option foo and you wanted to be set to bar, then you would enter:
foo=bar
(Do not use foo=bar
in your autorun.inf file as it is only an example, not a real option setting.)
That is all there really is to understand about the structure of an autorun.inf file. On to doing some actual cool stuff with it!
Setting a Custom Icon
To create a custom icon for your USB drive, use the icon
option. Set it to the name of the icon file.
Note: Since drive letters can change for USB drives, the file path is relative to the root of the drive. This means that if your USB drive is presently mounted on U: and your icon is located at U:\Icons\MyIcon.ico, then you would enter \Icons\MyIcon.ico for the value of this option.
For example, if you had an icon on the root of the USB drive called coffeecup.ico and you wanted this to be the icon that showed up for the USB drive, you would enter:
icon=coffeecup.ico
You are not limited to .ico files. If, for example, you have an executable with a nice icon, you can specify it as the icon file. For example:
icon=DCoTopen.exe
This is valid as long as DCoTopen.exe is available on the root of the USB drive.
Some files have more than one icon embedded in them. If this is the case, you can select which icon to use by specifing the index number after the file name. For example:
icon=iconlib.dll,2
This will use the second icon in the iconlib.dll file.
Naming Your USB Drive
If you would like your USB drive to display a specific name othr than the drive label created when it is formatted, use the label
option. For example, if I wanted to call my drive DCoT Drive, I would add this to my autorun.inf file:
label=DCoT Drive
Now, when you look at your USB drive in My Computer, it will say DCoT Drive by the drive letter.
Setting AutoPlay Options
AutoPlay is a relatively new function of Windows XP. It allows you to set up what file is run when the USB drive is plugged into the computer and the message that you are prompted with. There are two options that work in conjunction with AutoPlay. The first is open
. It specifies the program that you can run automatically with AutoPlay. So, if we wanted to run a program called DCoTopen.exe, you would add the this to your autorun.inf file:
open=DCoTopen.exe
The second option that we add is the message the user is prompted with. To set this, we use the action
option. If we want the message to say DCoT Open Program, add the following to autorun.inf:
action=DCoT Open Program
Once you have added this information, AutoPlay should look something like this:
Adding Context Menu Items
There are certain basic options such as Open and Explore that are available when you right click on a USB drive. But, wouldn’t it be cool to add your own? You can using a couple of lines in the autorun.inf file.
The first thing that we need to do is create an action, give it a name, and a message. We do all of this using the shell\verb
option. For example, let’s say that we would like to create an action called lost. It does not matter what the actin is called. It can be anything you want. We would also like to show the message Help! I’m Lost! in the context menu. We would simply add this line to autorun.inf:
shell\lost=Help! I'm Lost!
This will display Help! I’m Lost! in the context menu so that you can click on it. But, it doesn’t know what to do when you click on it. Tell the system by using shell\verb\command
option. In our example, we want to run the Lost.exe application. Adding this line will do the trick:
shell\lost\command=Lost.exe
You can add as many of these line pairs as you want to make the context menu as custom as you want.
Changing Default Action
When you double click on your USB drive, by default it will open up the drive so that you can browse through the files. Often, it is advantageous to perform some other action when the user double clicks the USB drive icon. You do this with the shell
option. If we wanted to run the Lost.exe program from the previous section automatically when we double clicked on the USB drive, we would add this line:
shell=lost
because lost is the name of the action that was specified in the earlier lines.
Viewing a File
If you wanted to view a file on your USB drive in the default application instead of running a program on the drive, you can substitute the open
option for the shellexecute
option. For example, if you wanted to open up a website called, oh, I don’t know, say http://www.DailyCupOfTech.com in the default web browser, you could user the following:
shellexecute=http://www.DailyCupOfTech.com
This will work for any file. This is the equivalent of using Start - Run… and then typing in a file name and clicking OK.
School’s Out, Time To Play!
That is about all there is to customizing the autorun.ing file. Now that you know what you are doing, it’s time to start playing! I have created the Autorun Dabbler’s Toolkit that you can play with.
Download the zip file and extract the contents to the root of an empty USB drive. You can now edit the autorun.inf and get it to do different things. Have fun!
Tuesday, February 26, 2008
Speed Up Your PC
5 ways to speed up your PC
By following a few simple guidelines, you can maintain your computer and keep it running smoothly. This article discusses how to use the tools available in Windows XP Service Pack 2 (SP2) and Windows Vista to more efficiently maintain your computer and safeguard your privacy when you're online.
On This Page
Free up disk space
By freeing disk space, you can improve the performance of your computer. The Disk Cleanup tool helps you free up space on your hard disk. The utility identifies files that you can safely delete, and then enables you to choose whether you want to delete some or all of the identified files.
Use Disk Cleanup to:
• | Remove temporary Internet files. |
• | Remove downloaded program files (such as Microsoft ActiveX controls and Java applets). |
• | Empty the Recycle Bin. |
• | Remove Windows temporary files. |
• | Remove optional Windows components that you don't use. |
• | Remove installed programs that you no longer use. |
Tip: Typically, temporary Internet files take the most amount of space because the browser caches each page you visit for faster access later.
To use Disk Cleanup
1. | Click Start, point to All Programs, point to Accessories, point to System Tools, and then click Disk Cleanup. If several drives are available, you might be prompted to specify which drive you want to clean. |
2. | In the Disk Cleanup for dialog box, scroll through the content of the Files to delete list. Choose the files that you want to delete. |
3. | Clear the check boxes for files that you don't want to delete, and then click OK. |
4. | When prompted to confirm that you want to delete the specified files, click Yes. |
After a few minutes, the process completes and the Disk Cleanup dialog box closes, leaving your computer cleaner and performing better.
Speed up access to data
Disk fragmentation slows the overall performance of your system. When files are fragmented, the computer must search the hard disk when the file is opened to piece it back together. The response time can be significantly longer.
Disk Defragmenter is a Windows utility that consolidates fragmented files and folders on your computer's hard disk so that each occupies a single space on the disk. With your files stored neatly end-to-end, without fragmentation, reading and writing to the disk speeds up.
When to run Disk Defragmenter
In addition to running Disk Defragmenter at regular intervals—monthly is optimal—there are other times you should run it too, such as when:
• | You add a large number of files. |
• | Your free disk space totals 15 percent or less. |
• | You install new programs or a new version of Windows. |
To use Disk Defragmenter:
1. | Click Start, point to All Programs, point to Accessories, point to System Tools, and then click Disk Defragmenter. Click Analyze to start the Disk Defragmenter. |
2. | In the Disk Defragmenter dialog box, click the drives that you want to defragment, and then click the Analyze button. After the disk is analyzed, a dialog box appears, letting you know whether you should defragment the analyzed drives. Tip: You should analyze a volume before defragmenting it to get an estimate of how long the defragmentation process will take. |
3. | To defragment the selected drive or drives, click the Defragment button. Note: In Windows Vista, there is no graphical user interface to demonstrate the progress—but your hard drive is still being defragmented. After the defragmentation is complete, Disk Defragmenter displays the results. |
4. | To display detailed information about the defragmented disk or partition, click View Report. |
5. | To close the View Report dialog box, click Close. |
6. | To close the Disk Defragmenter utility, click the Close button on the title bar of the window. |
Detect and repair disk errors
In addition to running Disk Cleanup and Disk Defragmenter to optimize the performance of your computer, you can check the integrity of the files stored on your hard disk by running the Error Checking utility.
As you use your hard drive, it can develop bad sectors. Bad sectors slow down hard disk performance and sometimes make data writing (such as file saving) difficult, or even impossible. The Error Checking utility scans the hard drive for bad sectors, and scans for file system errors to see whether certain files or folders are misplaced.
If you use your computer daily, you should run this utility once a week to help prevent data loss.
To run the Error Checking utility:
1. | Close all open files. |
2. | Click Start, and then click My Computer. |
3. | In the My Computer window, right-click the hard disk you want to search for bad sectors, and then click Properties. |
4. | In the Properties dialog box, click the Tools tab. |
5. | Click the Check Now button. |
6. | In the Check Disk dialog box, select the Scan for and attempt recovery of bad sectors check box, and then click Start. |
7. | If bad sectors are found, choose to fix them. |
Tip: Only select the "Automatically fix file system errors" check box if you think that your disk contains bad sectors.
Protect your computer against spyware
Spyware collects personal information without letting you know and without asking for permission. From the Web sites you visit to usernames and passwords, spyware can put you and your confidential information at risk. In addition to privacy concerns, spyware can hamper your computer's performance. To combat spyware, you might want to consider using Microsoft Windows Defender, which is included in Windows Vista, and is available as a free download for Microsoft XP SP2. Alternatively, there are other free anti-spyware software programs available.
Learn all about ReadyBoost
If you're using Windows Vista, you can use ReadyBoost to speed up your system. A new concept in adding memory to a system, it allows you to use non-volatile flash memory—like a USB flash drive or a memory card—to improve performance without having to add additional memory.
This articl is From Microsoft.