Microsoft KB Archive/884468

= How to programmatically obtain the installation state of Visual Studio .NET or Visual Studio 2005 =

Article ID: 884468

Article Last Modified on 1/10/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-





INTRODUCTION
This article describes how to programmatically obtain the installation state of Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.

Typically, you can examine a file or a registry entry to determine whether you have a version of Microsoft Visual Studio .NET or a version of Microsoft Visual Studio 2005, or of any program, already installed on your computer. You can also programmatically determine the version information by using Microsoft Windows Installer functions such as the MsiQueryProductState function. The MsiQueryProductState function takes the product code as the input parameter and then returns the installation state of the program.



MORE INFORMATION
To obtain the installation state of Visual Studio .NET or of Visual Studio 2005 on your computer, follow these steps:  Start Visual Studio .NET. On the File menu, point to New, and then click Project. The New Project dialog box appears. Under Project Types, click Visual Basic Projects or click Visual C# Projects.

Note In Visual Studio 2005, click Visual Basic or Visual C#. Under Templates, click Windows Application, and then click OK. By default, the following behavior occurs:  If you are using Microsoft Visual Basic .NET, the Form1 form and the Form1.vb file are created. If you are using Microsoft Visual C# .NET, the Form1 form and the Form1.cs file are created.</ul> </li> Add a TextBox control and a Button control to the Form1 form.</li> In Solution Explorer, right-click Form1.vb or Form1.cs, and then click View Code.</li>  Add the following code at the top of the file.

Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Imports System.Runtime.InteropServices Visual C# .NET or Visual C# 2005 using System.Runtime.InteropServices; </li>  Add the following code to the declarations section of the Form1 class.

Visual Basic .NET or Visual Basic 2005 <DllImport(&quot;msi.dll&quot;)> _ Public Shared Function MsiQueryProductState(ByVal szProduct As String) As Int32 End Function Visual C# .NET or Visual C# 2005 [DllImport(&quot;msi.dll&quot;)] public static extern Int32 MsiQueryProductState(string szProduct); </li>  In Design view of the Form1 form, double-click Button1, and then add the following code to the Button1_Click event procedure.

Visual Basic .NET or Visual Basic 2005 ' szProdCode is the product code. ' Include the product code in braces ({}). Dim szProdCode As String = TextBox1.Text.ToString.Trim Dim iErrorReturnQuerryState As Integer iErrorReturnQuerryState = MsiQueryProductState(szProdCode) MessageBox.Show(iErrorReturnQuerryState.ToString) Visual C# .NET or Visual C# 2005 // szProdCode is the product code. //Include the product code in braces ({}). string szProdCode = textBox1.Text.ToString.Trim; int iErrorReturnQuerryState=MsiQueryProductState(szProdCode); MessageBox.Show(iErrorReturnQuerryState.ToString); </li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start. The Form1 form appears.</li> Type the product code in the text box. For example, type {005F0409-6759-11D5-A54F-0090278A1BB8}. This is the product code for Microsoft Visual Studio .NET Enterprise Architect - English.</li> Click Button1.</li></ol>

You can obtain the installation state by comparing the return integer value with the following values.

<div class="references_section">