SIGN UP MEMBER LOGIN:    
ARTICLE

How to get System Environment information in WPF

Posted by Raj Kumar Articles | WPF with C# June 07, 2010
This article demonstrates how to get system environment information like Operating System,.NET Version, Machine Name, Username, Domain Name, Directory Name, Command Line using wpf.
Reader Level:
Download Files:
 

This article demonstrates how to get system environment information like Operating System,.NET Version, Machine Name, Username, Domain Name, Directory Name, Command Line using wpf.

Here we go, first of all create a new WPF Project.

Image1.jpg

Image1.

By default wpf application has some assembly

Image2.jpg

Image2.

Now let's start working on .xaml page. First of all add a namespace for mscorlib assembly.

xmlns:r="clr-namespace:System;assembly=mscorlib"

MSCorlib- It is special, any compiler needs it because it contains types that are required to make the language syntax work. System.Array, System.Int32, System.String, System.Exception, etc.

Write this .xamlcode on page:

<TextBlock>
<
Label Content="Operating System Version : "></Label>
<
Label Content="{x:Static r:Environment.OSVersion}"></Label>
<
LineBreak></LineBreak>
<
Label Content="Dot NET Version : "></Label>
<
Label Content="{x:Static r:Environment.Version}"></Label>
<
LineBreak></LineBreak>
<
Label Content="Machine Name : "></Label>
<
Label Content="{x:Static r:Environment.MachineName}"></Label>
<
LineBreak></LineBreak>
<
Label Content="User Name : "></Label>
<
Label Content="{x:Static r:Environment.UserName}"></Label>

<LineBreak></LineBreak>
<
Label Content="User Domain Name : "></Label>
<
Label Content="{x:Static r:Environment.UserDomainName}"></Label>
<
LineBreak></LineBreak>
<
Label Content="System Directory : "></Label>
<
Label Content="{x:Static r:Environment.SystemDirectory}"></Label>
<
LineBreak></LineBreak>
<
Label Content="Current Directory : "></Label>
<
Label Content="{x:Static r:Environment.CurrentDirectory}"></Label>
<
LineBreak></LineBreak>
<
Label Content="Command Line : "></Label>
<
Label Content="{x:Static r:Environment.CommandLine}"></Label>
</
TextBlock>

Run application:

Image3.jpg

Image3.

Here you can see operating system version, dot net version, machine name, user name, domain name, system directory name, current directory name, command line. Hope this will help you to get system environment information. If you have any question and doubts then drop me a line in c-sharpcorner comment section.

 

Login to add your contents and source code to this article
share this article :
post comment
 

I have *.exe I didn't install in my system but I can run that exe file, I want to make this application as single instance application and I have done it but the problem is that It is being executed whenever user account changes by using switchuser. I want to avoid this .exe file execution in different user accounts, while it is running in another user account. How can I do it please help me. kumar.rakam@yahoo.com Thank you in advance

Posted by kumara swamy rakam Aug 25, 2011

thank you. Looking for this information.

Posted by keith chee Jan 31, 2011

Quick and simple to follow. great article Raj

Posted by Drew Sheneman Jan 05, 2011

Sometimes i didn't express but it' s really important

Posted by nesrine meliene Dec 02, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor