VSTO & .NET & Excel

August 15, 2009

Check which Windows version is running

Filed under: .NET & Excel, VSTO & Excel — Dennis M Wallentin @ 12:51 pm

In the second edition of PED we introduce a new area; Creating Cross Version Applications. That is, to develop solutions that must run with all Excel versions and Windows versions using a single code base. I will not discuss how to code against different Excel versions. Instead I set focus on running .NET solutions on different Windows versions, i.e. Windows 2000/Windows XP and Windows Vista/Windows 7.  It should be noted that I have previously blogged how to check which Excel version that is installed.

With Windows 2000 and Windows XP we know that the user accounts are available in paths like:
C:\Documents and Settings\Dennis

In Windows Vista and Windows 7 the user accounts are located in  paths like:

Given this information we can rather easily code for different Windows versions in VB.NET. First we need to find out which Windows version that the targeting computers use. As the code shows below the namespace My.Computer once again comes to our rescue.

In the next step we retrieve the current user’s identity which is carried out by the SystemInformation namespace. Finally we put it together with the help from the StringBuilder namespace.

Code Windows Version and current user 1

When we run the code on a Windows Vista configuration we get the following information: 

Output when running on Windows Vista

When the User Access Control (UAC) is turned on (Windows Vista/Windows 7) we cannot access the c:\ root unless we run as administrator. But no matter the UAC status we can always access the current user’s folder system. In that way we can write and read files to the user’s folders in addition to the above.

Kind regards,



  1. Another way to obtaining your Application Data folder is expanding the %APPDATA% variable from your environment.

    Comment by dutchgemini — August 18, 2009 @ 2:44 pm

  2. Thanks for reminding me about it 🙂

    Kind regards,

    Comment by Dennis Wallentin — August 20, 2009 @ 5:49 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: