Sunday, August 16, 2009

Difference between Convert.ToString and .ToString()

The following example describes the difference.


int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));

We can convert the integer “i” using “i.ToString()” or “Convert.ToString”.
The basic difference between “i.ToString()” and “Convert.ToString” is “Convert” function handles NULLS while “i.ToString()” does not and it will throw a NULL reference exception error. Hence the good coding practice is using “convert” which is always safe.

Caching in ASP.NET

ASP.NET provides a feature called Caching that improves the performance of web applications by minimizing the usage of server resources . It also reduces the database hits and thereby renders the page faster. There are different types of caching. They are

* Page Output Caching
* Page Fragment Caching
* Data Caching


Page Output Caching

Using this concept the page is cached using an Output Cache engine and all subsequent requests are served from the cache. If whenever a new request comes, this would check if there is a corresponding cache entry for this page. If it finds a corresponding cache entry for the page, the page is rendered from the cache, if not the page being requested is rendered dynamically i.e, the page takes a round trip.

For static Pages this technique will be useful.

Page output caching can be implemented in either of the following two ways:

* At design time using the OutputCache directive

* At runtime using the HttpPolicy class

Following is the syntax of page output caching directive

<%@ OutputCache Duration="no of seconds" Location="Any | Client | Downstream | Server | None" VaryByControl="control" VaryByCustom="browser |customstring" VaryByHeader="headers" VaryByParam="parameter" %>


Following statement is used to implement output caching in an aspx page at design time. The directive is placed at the top of the .aspx page.

<%@OutputCache Duration="30" VaryByParam="none" %>

In the example above the Duration parameter specifies for how long the page would be in cache and the VaryByParam parameter is used to cache different views of the page. Cache duration is a required field, and must be set to an integer greater than zero. The VaryByParam parameter, which is also required, specifies whether the cached page would differ in versions based on any parameter. A value of * in the same parameter indicates that the page would be cached based on all the Get/Post parameters. We can also specify one or more Get/Post parameter(s). Hence, the same statement shown above can have the following variations. The VaryByParam parameter is particularly useful in situations where we require caching a page based on certain criteria. As an example, we might require to cache a specific page based on the CustomerID.

<%@OutputCache Duration="30" VaryByParam="*" Location = "Any"%>
<%@OutputCache Duration="30" VaryByParam="CustomerID" Location = "Client" %>
<%@OutputCache Duration="30" VaryByParam="CustomerID";Basic" %>


The VaryByParam parameter can also have multiple parameters as shown in the example above.

The location parameter is used to specify the cache location, either the server of the client.

To set a page's cacheability programmatically we have to use the method Response.Cache.SetCacheability. This method accepts the following parameters

* NoCache

* Private

* Public

* Server

The code snippet below shows how to set a page’s cacheability programmatically:

Response.Cache.SetCacheability(HttpCacheability.Server);

Additionally we can set other properties which map to the same fields available when using the OutputCache directive on the page:

Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
Response.Cache.SetValidUntilExpires(true);
Response.Cache.VaryByParams["ID"]= true;


Page Fragment Caching

If you wish to cache a portion of the page then use this method than caching the whole page. This is useful in situations where we can have a page that contains both static and dynamic content.

<%@ OutputCache Duration="15" VaryByControl="EmpID;DeptID" VaryByParam="*"%>

The above code should be placed at the top of any User Control (.axcx file).


Data Caching

The following method checks the Cache whether the data is present in the Cache. If the data is present in the Cache then it fills the Dataset from he Cache else it fills the DataSet from the database and then populates Cache.

public DataSet GetBooks()
{
string cacheKey = "BooksInfo";
DataSet ds = Cache[cacheKey] as DataSet;
if (ds == null)
{
ds = SelectBooks(); // This method fills the DataSet from the Database.
Cache.Insert(cacheKey, ds, null, NoAbsoluteExpiration,
TimeSpan.FromHours(15),CacheItemPriority.High, null);
}
return ds;
}


Cache Expirations

The Cache expirations can be of the following types

* Time Based Expiration

* Dependency Based Expiration

Time Based Expiration

This is used to specify a specific period of time for which the page would remain in the cache. The following statement specifies such expiration for a page in the code behind of a file using C#.

Response.Cache.SetExpires(DateTime.Now.AddSeconds(120));

It can also be accomplished by stating the same in the output cache directive as shown here.

<%@OutputCache Duration="60" VaryByParam="None" %>


Wednesday, August 12, 2009

Network Access After Norton Anti-Virus Install


Network Access After Norton Anti-Virus Install


Sometimes you can't access a WinXP computer after installing Norton Anti-Virus.
This is because there might be a variety of errors at the other computer depending on the operating system. On the XP computer, in the Event Viewer / System log, there will be the following error:

The server's configuration parameter "irpstacksize" is too small for the server to use a local device. To fix this do the following steps.

Open Registry Editor

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters

Now edit the "IRPStackSize" and enter the value as 15. Reboot the computer.

Not Displaying Startup and Shutdown Status Message


Not Displaying Logon, Logoff, Startup and Shutdown Status Messages



Open Registry Editor

Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system

If it is not there, then create a new DWORD value named "DisableStatusMessages" and enter value as 1.

Power of During Shutdown


Poweroff at Shutdown


If your computer does not turn off the power when doing a shutdown,
you may need to edit the registry.

Open Registry Editor

Go to HKEY_CURRENT_USER\Control Panel\Desktop

Now edit the key "PowerOffActive" and give it a value of 1

You can also do the same by Navigating to HKEY_USERS\.DEFAULT\Control Panel\Desktop.

Disable Shared Documents


Disable Shared Documents

If you want to disable the Shared Documents folder that shows up on the network, do the following.

Open Registry Editor

Go to HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Policies \ Explorer \

Now create a new DWORD Value and give it the name "NoSharedDocuments'
Enter a value of 1 and then Log off or reboot the computer.

Disable Thumpnail View in Explorer


Disable Explorer Thumbnail View


If you want disable the Explorer's ability to show the Thumbnail View,

Open Registry Editor

Go to HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced \

Change the value of ClassicViewState to 1 .

Clear Page File on Shutdown

To clear the page file on each shutdown do the following steps

Start Registry Editor

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\ClearPageFileAtShutdown

Now set the value to 1

Classic Search in Exporer

Using the Classic Search in Explorer

If you want to use the classic search style in Explorer, then

Open Registry Editor

Go to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState

Now add a new String Key called "Use Search Asst"

Give it a value of "no Go to top"

Changing Registered Owner

Changing the Registered Owner

To Change the Name of the Registered Owner follow the steps as follows.

OpenRegistry Editor

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

Here you can edit the name in the Registered Owner key

Hide or Unhide Logon Names

Hide or Unhide Logon Names

If you wish to hide or unhide the names of users that are displayed on the logon screen do the following steps.

Open Registry Editor

Go to HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon \ SpecialAccounts \ UserList

Now add a new DWORD with the name of the user account you want to . Also make sure it has a value of 0. If there is an existing account, you can unhide it by giving it a value of 1.

Increasing System Performance

Increasing System Performance

If you have 512 MB or more of memory, you can increase system performance
by having the core system kept in memory.

Open Registry Editor

Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\DisablePagingExecutive

Now Set the value to 1 and Restart the computer.

Automatically End up Tasks

Automatically Ending Non-Responsive Tasks

Open Registry Editor

Navigate to HKEY_CURRENT_USER\Control Panel\Desktop\AutoEndTasks

Now set the value to be 1

Also change the "WaitToKillAppTimeout" to the number of milliseconds you want.

Change Internet Explore Title

If you wish to change the title of your Internet Explorer, do the following steps.

Open Regedit

Go to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Window Title

Enter the name which you want to appear in the title bar

Tuesday, August 11, 2009

Enable or Disable Task Manager

If you wish to Enable or Disable the Task Manager

Open Registry Editor

Go to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System

Now create a new Dword value named "DisableTaskMgr" and give it a value of 0 to enable it.
To disable it give a vaule of 1.

Most Frequently used programs list

Windows XP features the most frequently used programs list, which is designed to provide access to the programs you use the most.
XP provides you with only two configuration options: the ability to completely clear the list and the ability to specify the maximum number of programs that can appear on this list at any one time. However, you may also want to prevent certain applications, such as Calculator and Notepad, from appearing on the list.

Also you can prevent an application from appearing in the Start menu's most frequently used programs list by adding a special key to the registry. Here's how:

1. Open Registry Editor.
2. Go to HKEY_CLASSES_ROOT\Applications.
3. Right-click on the Applications key and select New | Key.
4. Give the key the same name as the application's executable file.
5. Right-click your new key and select New | String Value.
6. Name the string value NoStartPage.
7. Close the Registry Editor.
8. Reboot or log off and log back on for the change to take effect.

Monday, August 10, 2009

Chanakya Quotes

“A good wife is one who serves her husband in the morning like a mother does, loves him in the day like a sister does and pleases him like a prostitute in the night.“


“A man is born alone and dies alone; and he experiences the good and bad consequences of his karma alone; and he goes alone to hell or the Supreme abode.“


“A man is great by deeds, not by birth.“


“A person should not be too honest. Straight trees are cut first and honest people are screwed first.“


“As a single withered tree, if set aflame, causes a whole forest to burn, so does a rascal son destroy a whole family.“


“As long as your body is healthy and under control and death is distant, try to save your soul; when death is immanent what can you do?“


“As soon as the fear approaches near, attack and destroy it.“


“Before you start some work, always ask yourself three questions - Why am I doing it, What the results might be and Will I be successful. Only when you think deeply and find satisfactory answers to these questions, go ahead.“


“Books are as useful to a stupid person as a mirror is useful to a blind person.“


“Do not be very upright in your dealings for you would see by going to the forest that straight trees are cut down while crooked ones are left standing.“


“Do not reveal what you have thought upon doing, but by wise council keep it secret being determined to carry it into execution.“


“Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth.“


“Even if a snake is not poisonous, it should pretend to be venomous.“


“God is not present in idols. Your feelings are your god. The soul is your temple.“


“He who is overly attached to his family members experiences fear and sorrow, for the root of all grief is attachment. Thus one should discard attachment to be happy.“


“He who lives in our mind is near though he may actually be far away; but he who is not in our heart is far though he may really be nearby.“


“If one has a good disposition, what other virtue is needed? If a man has fame, what is the value of other ornamentation?“


“It is better to die than to preserve this life by incurring disgrace. The loss of life causes but a moment's grief, but disgrace brings grief every day of one's life.“


“Never make friends with people who are above or below you in status. Such friendships will never give you any happiness.“


“O wise man! Give your wealth only to the worthy and never to others. The water of the sea received by the clouds is always sweet.“


“Do not keep company with a fool for as we can see he is a two-legged beast. Like an unseen thorn he pierces the heart with his sharp words.”


“Purity of speech, of the mind, of the senses, and the of a compassionate heart are needed by one who desires to rise to the divine platform.”


“One whose knowledge is confined to books and whose wealth is in the possession of others, can use neither his knowledge nor wealth when the need for them arises.”


“Before you start some work, always ask yourself three questions - Why am I doing it, What the results might be and Will I be successful. Only when you think deeply and find satisfactory answers to these questions, go ahead.”


“The happiness and peace attained by those satisfied by the nectar of spiritual tranquillity is not attained by greedy persons restlessly moving here and there.”


“Do not be very upright in your dealings for you would see by going to the forest that straight trees are cut down while crooked ones are left standing.”


“A person should not be too honest. Straight trees are cut first and honest people are screwed first.”


“The serpent, the king, the tiger, the stinging wasp, the small child, the dog owned by other people, and the fool: these seven ought not to be awakened from sleep.”


“Once you start a working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest.“


“One whose knowledge is confined to books and whose wealth is in the possession of others, can use neither his knowledge nor wealth when the need for them arises.“


“Purity of speech, of the mind, of the senses, and of a compassionate heart are needed by one who desires to rise to the divine platform.“


“Test a servant while in the discharge of his duty, a relative in difficulty, a friend in adversity, and a wife in misfortune.“


“The biggest guru-mantra is: never share your secrets with anybody. It will destroy you.“


“The earth is supported by the power of truth; it is the power of truth that makes the sun shine and the winds blow; indeed all things rest upon truth.“


“The fragrance of flowers spreads only in the direction of the wind. But the goodness of a person spreads in all direction.“


“The happiness and peace attained by those satisfied by the nectar of spiritual tranquillity is not attained by greedy persons restlessly moving here and there.“


“The life of an uneducated man is as useless as the tail of a dog which neither covers its rear end, nor protects it from the bites of insects.“


“The one excellent thing that can be learned from a lion is that whatever a man intends doing should be done by him with a whole-hearted and strenuous effort.“


“The serpent, the king, the tiger, the stinging wasp, the small child, the dog owned by other people, and the fool: these seven ought not to be awakened from sleep.“


“The wise man should restrain his senses like the crane and accomplish his purpose with due knowledge of his place, time and ability.“


“The world's biggest power is the youth and beauty of a woman.“


“There is no austerity equal to a balanced mind, and there is no happiness equal to contentment; there is no disease like covetousness, and no virtue like mercy.“


“There is poison in the fang of the serpent, in the mouth of the fly and in the sting of a scorpion; but the wicked man is saturated with it.“


“There is some self-interest behind every friendship. There is no friendship without self-interests. This is a bitter truth.“


“Treat your kid like a darling for the first five years. For the next five years, scold them. By the time they turn sixteen, treat them like a friend. Your grown up children are your best friends.“


“We should not fret for what is past, nor should we be anxious about the future; men of discernment deal only with the present moment.“


“Whores don't live in company of poor men, citizens never support a weak company and birds don't build nests on a tree that doesn't bear fruits.“


“He who is overly attached to his family members experiences fear and sorrow, for the root of all grief is attachment. Thus one should discard attachment to be happy.”


“The one excellent thing that can be learned from a lion is that whatever a man intends doing should be done by him with a whole-hearted and strenuous effort.”


“We should not fret for what is past, nor should we be anxious about the future; men of discernment deal only with the present moment.”


“The fragrance of flowers spreads only in the direction of the wind. But the goodness of a person spreads in all direction.”


“The world's biggest power is the youth and beauty of a woman.”


“The life of an uneducated man is as useless as the tail of a dog which neither covers its rear end, nor protects it from the bites of insects.”


“A man is born alone and dies alone; and he experiences the good and bad consequences of his karma alone; and he goes alone to hell or the Supreme abode.”


“Even as the unborn babe is in the womb of his mother, these five are fixed as his life destiny: his life span, his activities, his acquisition of wealth and knowledge, and his time of death.”


“If one has a good disposition, what other virtue is needed? If a man has fame, what is the value of other ornamentation?”


“Moral excellence is an ornament for personal beauty; righteous conduct, for high birth; success for learning; and proper spending for wealth.”


“As a single withered tree, if set aflame, causes a whole forest to burn, so does a rascal son destroy a whole family.”


“It is better to die than to preserve this life by incurring disgrace. The loss of life causes but a moment's grief, but disgrace brings grief every day of one's life.”


“He who shall practice these twenty virtues shall become invincible in all his undertakings.”


“Scriptural lessons not put into practice are poison; a meal is poison to him who suffers from indigestion; a social gathering is poison to a poverty stricken person; and a young wife is poison to an aged man.”


“Knowledge is lost without putting it into practice; a man is lost due to ignorance; an army is lost without a commander; and a woman is lost without a husband.”


“Rain which falls upon the sea is useless; so is food for one who is satiated; in vain is a gift for one who is wealthy; and a burning lamp during the daytime is useless.”


“O wise man! Give your wealth only to the worthy and never to others. The water of the sea received by the clouds is always sweet.”


“The wise man should restrain his senses like the crane and accomplish his purpose with due knowledge of his place, time and ability.”


“What is it that escapes the observation of poets? What is that act women are incapable of doing? What will drunken people not prate? What will not a crow eat?”


“As long as your body is healthy and under control and death is distant, try to save your soul; when death is immanent what can you do?”


“Although an ass is tired, he continues to carry his burden; he is unmindful of cold and heat; and he is always contented; these three things should be learned from the ass.”


“O lady, why are you gazing downward? Has something of yours fallen on the ground? (She replies) O fool, can you not understand the pearl of my youth has slipped away?”


“Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth.”

Sunday, August 9, 2009

Registry Tips

Note: Editing the registry is risky, be sure you have a verified backup before saving any changes.

Registry Hacking Tips

To open Registry editor type “regedit” in run window (You can open run window by simply pressing the windows key followed by the button “R” or point to Start menu and click “Run”) .

Display legal notice on startup:

If your friends login to your computer in your absence and if you wish to tell them, what to do and what not to do, you can do it easily by displaying a legal notice at system start up.
Open Registry editor and navigate to the menu as follow

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system]

Now change the values shown below

"legalnoticecaption"="Type your notice caption"
"legalnoticetext"="Type your legal notice text"


Automatic Administrator Login:

This is a good trick which you can use to prove Windows XP is not secure as multi-user operating system. If you can access to registry editor in a system from any account you can set the account as administrator account. In registry editor navigate as follows.


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]

Now set the

"AutoAdminLogon"="1"

Friday, August 7, 2009

Run Commands


Accessibility Controls -- access.cpl

Add Hardware Wizard -- hdwwiz.cpl

Add/Remove Programs -- appwiz.cpl

Administrative Tools -- control admintools

Automatic Updates -- wuaucpl.cpl

Bluetooth Transfer -- Wizard fsquirt

Calculator -- calc

Certificate Manager -- certmgr.msc

Character Map -- charmap

Check Disk Utility -- chkdsk

Clipboard Viewer -- clipbrd

Command Prompt -- cmd

Component Services -- dcomcnfg

Computer Management -- compmgmt.msc

Date and Time Properties -- timedate.cpl

DDE Shares -- ddeshare

Device Manager -- devmgmt.msc

Direct X Control Panel (If Installed)* -- directx.cpl

Direct X Troubleshooter -- dxdiag

Disk Cleanup Utility -- cleanmgr

Disk Defragment -- dfrg.msc

Disk Management -- diskmgmt.msc

Disk Partition Manager -- diskpart

Display Properties control -- desktop

Display Properties -- desk.cpl

Display Properties (w/Appearance Tab Preselected) -- control color

Dr. Watson System Troubleshooting -- Utility drwtsn32

Driver Verifier -- Utility verifier

Event Viewer -- eventvwr.msc

File Signature Verification Tool -- sigverif

Findfast -- findfast.cpl

Folders Properties -- control folders

Fonts control -- fonts

Fonts Folder -- fonts

Free Cell Card Game -- freecell

Game Controllers -- joy.cpl

Group Policy Editor (XP Prof -- ) gpedit.msc

Hearts Card Game -- mshearts

Iexpress Wizard -- iexpress

Indexing Service -- ciadv.msc

Internet Properties -- inetcpl.cpl

IP Configuration (Display Connection Configuration) -- ipconfig /all

IP Configuration (Display DNS Cache Contents) -- ipconfig /displaydns

IP Configuration (Delete DNS Cache Contents) -- ipconfig /flushdns

IP Configuration (Release All Connections) ipconfig /release

IP Configuration (Renew All Connections) -- ipconfig /renew

IP Configuration (Refreshes DHCP & Re-Registers DNS) -- ipconfig /registerdns

IP Configuration (Display DHCP Class ID) -- ipconfig /showclassid

IP Configuration (Modifies DHCP Class ID) -- ipconfig /setclassid

Java Control Panel (If Installed) -- jpicpl32.cpl

Java Control Panel (If Installed) -- javaws

User Account Management -- nusrmgr.cpl

Utility Manager -- utilman

Windows Firewall -- firewall.cpl

Windows Magnifier -- magnify

Windows Management Infrastructure -- wmimgmt.msc

Windows System Security Tool -- syskey

Windows Update Launches -- wupdmgr

Windows XP Tour Wizard -- tourstart

WordPad -- write



Speed up Windows XP's defrag operations


One simple way to speed up the defrag operation in Windows XP is to restart your computer before you launch Defrag. Doing so allows the operating system to clear out the swap/paging file and reset it to the default size. Hence Defrag focus strictly on the necessary data on the hard disk without having to stop and manage a huge swap file loaded with unneeded data.
An alternate approach of speeding up the defrag operation in Windows XP is to configure it to occur immediately upon startup. You can do so easily using registry edit:

1. Open the Registry Editor by typing “regedit” in Run window. Registry Editor window opens.

2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce.

3. Now Right-click on the “RunOnce” subkey and select New  String Value.

4. Name the new String value as “Defrag” and hit “Enter” twice.

5. Next type Defrag.exe c: /f in the Value Data text box and click OK.

6. After finishing Close the Registry Editor and restart Windows.

The above method can be used for both Windows XP Home and Professional Editions.



Remove Pen Drive Virus


Viruses such as “autorun” and “Ravmon” virus mostly affect the pen drive. Most of the Antivirus does not detect such kind of viruses. Such viruses are spread mostly through pen drive. So now you can protect your computer from such kind of viruses by doing the following steps.

1. Plug your USB drive in your system.
2. You will be prompted by a dialog box as shown below.























3. If you can see the dialog box just click Cancel. Don’t try to open your pen drive.
4. If you were not able to view the dialog box do nothing, just check whether your pen drive appears in My Computer window. Don’t try to open your pen drive. If you could not able see your pen drive try to remove and plug it again.
5. Now go to Start--> Run and type cmd to open the Command Prompt window.
6. Go to My Computer and Check the Drive letter of your USB drive or Pen Drive. (E.g. If it is written Transcend (J :) , then J: will be the drive letter.)
7. Type the drive letter followed by a colon (e.g “J:”) inn the Command Window and Hit Enter.
8. Then type dir/w/o/a/p and Hit Enter
9. Now you will get a list of files. In the list of files, search if anyone of the following exist


a.Autorun.inf
b.NewFolder.exe
c.Bha.vbs
d.Iexplore.vbs
e.Info.exe
f.New_Folder.exe
g.Ravmon.exe
h.RVHost.exe or any other files with .exe Extension .


10. If you could find any one of the files above, Run the command attrib -h -r -s -a *.* and Hit Enter.
11. Next type the following command to delete each File.
12. The Command to type is del filename (E.g. del autorun.inf).
Now you are done and your USB drive is virus free. Scan your pen drive using any antivirus tool to check whether it is virus free.


Enabling Capslock, Numlock and Scroll Lock in System Startup


If you wish to enable the startup state of CapsLock, NumLock and ScrollLock keys do the following steps.
1. Open Registry editor by typing regedit in run window.
2. Navigate to HKEY_CURRENT_USER \ Control Panel \ Keyboard.
3. Open InitialKeyboardIndicators
4. Now change the values as follows


a. 0 - All Keys off
b. 1 - Caps Lock on
c. 2 - Num Lock on
d. 4 - Scroll Lock on
e. 3 - Caps Lock and Num Lock on
f. 5 - Caps Lock and Scroll Lock on
g. 6 - Num Lock and Scroll Lock on
h. 7 - Caps Lock, Num Lock, and Scroll Lock on

After you have changed the values logoff or restart your system for the changes to take effect.


Windows Explorer opens Search instead of folder



Windows Explorer sometimes opens Search companion instead of folder. This may be caused due to invalid settings for opening folder. It can also be caused due to some external programs (virus).
To overcome this start registry editor by typing “regedit” in run window.
ie) Start --> Run --> regedit and press Enter.
Now the registry window opens. Navigate to HKEY_CLASSES_ROOT \ Directory \ shell. Edit the default value to be explorer or none.


Common Control Panel Applets



Following are some common Control Panel Applets that are located in the \windows\system32 directory. Try using the following if you don’t wish to open Control Panel window and then choose the items from it.

appwiz.cpl -->>Add/Remove Programs
desk.cpl -->> Display Properties
firewall.cpl -->> Firewall Settings
inetcpl.cpl -->> Internet Options
mmsys.cpl -->> Sound and Audio
ncpa.cpl -->> Network Connections
nusrmgr.cpl -->> User Accounts
powercfg.cpl -->> Power Options
sysdm.cpl -->>System Properties
wscui.cpl -->> Security Center
wuaucpl.cpl -->> Automatic Updates Configuration Go to Top



Changing User Account Password from Command Prompt



Use Account Password can be changed from the Command Prompt on any system which runs on Windows NT 4.0, Windows 2000, Windows XP and Windows Server 2003. This method works for computers which has the User Account on a workstation, a stand-alone server, or a Windows domain controller. The only thing you have to do is that you must log in as an Administrator and type the following in Command Prompt. Use your own username.

net user sanjay * /domain

It prompts for a password. Type a new password and not the existing password. After you type the password the system prompts you for the confirmation to type the password again. Type again the same password and it’s done. Now your password has changed successfully.
Also if you don’t wish to prompt for the confirmation of password type the following in command prompt.

net user sanjay abcdef /domain

You can also change the password of a batch file using the above command. Also if you didn’t add /domain switch on a member server or workstation, the command will be performed on the local SAM and not on DC SAM.

If you wish to change the password for Administrator account, check whether you have logged in as a administrator and type the following.

net user administrator abcdef

If you are not the administrator you receive an error message stating “Access Denied”.


Monday, August 3, 2009

DataGridView Key Press Events

I came across a problem where i have to fire the Key Press event for DataGrid. But Unforyunately the DataGridView does not conatin an event like 'CellKeyPress' to capture a cell's KeyPress event, since there are several kinds of cells, e.g. DataGridViewTextBoxCell, DataGridViewComboBoxCell,DataGridViewCheckBoxCell etc, and also not all DataGridView cells should have the 'KeyPress' event.

Instead there is an alternate event provided by DataGridView named "EditingControlShowing", which brings us the inner editing control the
current cell is holding. Hence we could get the editing control by handling the
EditingControlShowing event and then subscribe the KeyPress event of the
editing control.


private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
TextBox txtbox = e.Control as TextBox;
if (txtbox != null)
{
txtbox.KeyPress += new KeyPressEventHandler(txtbox_KeyPress);
}
}

private void txtbox_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show(e.KeyChar.ToString());
}


DataGridView Cells to accept only Integer Value

The following code checks the Datagrid Cells to accept only integer values.


private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
TextBox txtbox = e.Control as TextBox;
if (txtbox != null)
{
//Event to fire up if the Control is a TextBox
txtbox.KeyPress += new KeyPressEventHandler(txtbox_KeyPress);
}
}

private void txtbox_KeyPress(object sender, KeyPressEventArgs e)
{
string str = "/b0123456789"; // Holds Integer Values
e.Handled = !(str.Contains(e.KeyChar.ToString()));
}


Remove Integer Validation for a Particular Cell in DataGrid



private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
TextBox txtbox = e.Control as TextBox;
if (txtbox != null)
{
if ((dgrd.CurrentCell.ColumnIndex) == 1)
{
//Event to fire up if the Control is a TextBox & ColumIndex is 1.
txtbox.KeyPress += new KeyPressEventHandler(txtbox_KeyPress);
}
else
{
//Removes the event for the Control if the ColumIndex is not 1.
txtbox.KeyPress -= new KeyPressEventHandler(txtbox_KeyPress);
}
}
}

private void txtbox_KeyPress(object sender, KeyPressEventArgs e)
{
string str = "/b0123456789"; // Holds Integer Values
e.Handled = !(str.Contains(e.KeyChar.ToString()));
}

.