Geeks With Blogs

WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Inside and Out... An attempt to understand technology better...
VB 2005 is introducing the concept of My that allows the developer to write code which can get details pertaining to currently logged in user - for instance, the MyComputerInfo class allows you to get details like your machine's name, total physical and virtual memory, available memory, etc. Likewise, MyAudio is another class that provides you functionality to play audio on your system.

My does not give you any new functionality - it simply saves the developer from delving deep inside the FCL to get the same information which My will give you in a single namespace. However, this functionality is available to VB 2005. What about other managed languages? Can't they use it?

And the answer is yes! They can. All you have to do is set a reference to Microsoft.VisualBasic.dll assembly and use the Microsoft.VisualBasic.MyServices namespace. Below is sample C# source code that illustrates the use of My in C#:

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic.MyServices; // this contains the "My" classes


namespace MyCSDemo
    class Program
        static void Main(string[] args)
            MyComputerInfo refMCInfo = new MyComputerInfo();
            ulong ulMB = 1024*1024;

            Console.WriteLine("Machine Name: {0}", refMCInfo.MachineName);
            Console.WriteLine("Physical Memory: {0} MB", refMCInfo.TotalPhysicalMemory / ulMB);
            Console.WriteLine("OS: {0} Version: {1}", refMCInfo.OSFullName, refMCInfo.OSVersion);
Posted on Monday, November 1, 2004 8:00 PM .NET Framework | Back to top

Comments on this post: Using "My" in C# (and other managed languages)

# re: Using "My" in C# (and other managed languages)
Requesting Gravatar...
But what about the new VB startup model and application events?

I have detailed coverage of this here:
Left by Daniel Moth on Nov 01, 2004 9:05 PM

# C# でも My
Requesting Gravatar...
C# ?? My
Left by 米田 Blog ( SQL Server MEMO ) on Nov 02, 2004 8:43 AM

# re: Using "My" in C# (and other managed languages)
Requesting Gravatar...
Thanks man, you saved me !! :-)

But your code didn't work -
"undefined type MyComputerInfo".

But it helped me find this, I hope you enjoy it.

Thanks again!

string strHostName = Dns.GetHostName();
string hostIPs = string.Empty;
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
// Enumerate IP addresses
foreach (IPAddress ipaddress in iphostentry.AddressList)
hostIPs += (ipaddress.ToString() + " ");

ComputerInfo hostInfo = new ComputerInfo();
ulong ulMB = 1024 * 1024;
Clock hostClock = new Clock();
Network hostNetwork = new Network();
ServerComputer hostServer = new ServerComputer();

string result = string.Format("Host <{0}>, IPs <{1}>, OS ver <{2}>, Free Physical Memory <{3} MB>" +
", Free Virtual Memory <{4} MB>, GMTTime <{5}>",
strHostName, hostIPs, Environment.OSVersion.ToString(), hostInfo.AvailablePhysicalMemory / ulMB,
hostInfo.AvailableVirtualMemory / ulMB, hostClock.GmtTime());
Left by Ofer on Feb 26, 2007 2:40 PM

# re: Using "My" in C# (and other managed languages)
Requesting Gravatar...
Where can I download or find the .dll you reference to use "My" ? (doesn't automatically install w/ VS 2005 Professional Edition)
Left by Ira on Jun 01, 2007 12:58 PM

Your comment:
 (will show your gravatar)

Copyright © Gaurav Khanna | Powered by: