Thursday, March 22, 2007

How to get the machine name, user name, OS etc. in .net?

Simple one., but worth mentioning it... How to get the machine name, user name, OS etc. in .net?

Use of System.Environment!

System.Environment:

This Class is used to get the information about current logged in user in the Windows. that is this class will get all the information about the current user in the windows. it is also used to get the info about the Machine and its Harddrive and other information.

Frequently used Methods and Properties
System.Environment.UserName - To get the Current logged in user name and his ID.
System.Environment.Version - To get the Current Version of CLR
System.Environment.UserDomainName - To get the Domain Naem associated with the current user.
System.Environment.SystemDirectory - Fully Qualified Path of SYS. Directory
System.Environment.OSVersion - To get the OS version
System.Environment.MachineName - To get the Machine name
System.Environment.GetLogicalDrives() - To get the Logical Drives of the Computer
System.Environment.Exit - To Exit the Current Process
There are lot of properties and functions available apart from this, please browse through in .net.

Cheers - Dipesh

Wednesday, March 07, 2007

Debugging .net windows service

Ever faced by the challenge of debugging windows service autmatically. These lines of code below in the main routine of your windows service will help you break in to the debug mode. This is pretty helpful when you want to debug and test your win service without actually deploying it on the box as well.

static void Main()
{
#if (!DEBUG)
ServiceBase.Run(new WindowsService());
#else
System.Diagnostics.Debugger.Break();
ServiceBase.Run(new WindowsService());
#endif
}

Check the MS site for step by step debugging win service... http://msdn2.microsoft.com/en-us/library/7a50syb3(VS.80).aspx

Credits - Swati for bringing this to my attention! :)
Thanks - Dipesh

Tuesday, March 06, 2007

ReadKey() in Console apps

Color me if you doubt this! But i came across this while i was working on Console application!
2 cents - If you want to break your console app before in .net or VB you used to specify:
Console.Read //or sometimes Console.Readline;

It meant that you can press any key to continue but it is actually "Enter" key that need to be pressed to exit out of the app! :)

However, there was a workaround to take in any key other than Enter key but you had to go through the API core to get stuff working. Now, in .net 2.0 Microsoft recoginized this and has attempted to come up with elegant solution by providing ReadKey() method.

Console.ReadKey(); accepts any key :) More below -
http://msdn2.microsoft.com/en-us/library/system.console.readkey(vs.80).aspx

Cheers - Dipesh

Thursday, March 01, 2007

EntLibs 3.0 CTP released just after the day "Orcas" is released...

Welcome March... I bet this is going to be really a rocking and an exciting month. It is personally for me! :)

However, we have EntLibs CTP released...
Includes a preview of the new Policy Injection Application Block, and release candidate of all other application blocks. More details are in the included documentation and release notes.

You can download the Entlibs, documentation and more details at http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=2081

Runtime Binaries
Enterprise Library 3.0 February 2007 CTP - 472 Downloads dated today (9.8 MB)
Documentation
Release Notes - 164 Downloads dated today (66.3 KB)

Cheers - D

Visual Studio Orcas March CTP released...

Welcome March...

Microsoft Pre-release Software Visual Studio Code Name "Orcas" - March 2007 Community Technology Preview (CTP) is available here...

http://www.microsoft.com/downloads/details.aspx?familyid=b533619a-0008-4dd6-9ed1-47d482683c78&displaylang=en&tm