Microsoft KB Archive/315487

= How to run an existing Visual Studio .NET or Visual Studio 2005 Wizard by using DTE.LaunchWizard =

Article ID: 315487

Article Last Modified on 1/12/2006

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ 2005 Express Edition

-



This article was previously published under Q315487



SUMMARY
The sample code provided in this article demonstrates how to use the LaunchWizard method of the DTE object to run an existing Microsoft Visual Studio .NET Wizard.



MORE INFORMATION
The DTE.LaunchWizard method requires two arguments when used to run a new project wizard. The first argument is the name of the wizard file (.vsz file). The second argument is an array of values that is passed to the wizard when it runs. When you set the seventh element of the array to True, you can force the errors to throw exceptions, which may be caught in a try...catch structure. The New Windows Application Wizard expects the following values in the array:
 * WizardType: a GUID indicating the type of wizard. For a new project wizard, the GUID is {0F90E1D0-4999-11D1-B6D1-00A0C90F2744}.
 * ProjectName: a string for the name of the new project.
 * Local directory: a string containing the full path to the folder where the new project will be created.
 * Installation directory: a string containing the folder where Visual Studio is installed.
 * Exclusive: a Boolean value indicating whether any existing open solution should be closed.
 * Solution name: a string name for the solution file, without a path or extension.
 * Silent: a Boolean indicating whether the wizard should run silently.

The following macro shows how to use the LaunchWizard method to run the existing wizard.

NOTE: The macro uses the Silent flag when calling the wizard. If you run this macro once, it runs without error, provided that the directory and project do not already exist. If you run this macro a second time, an error is raised. Because the Silent flag is set to True, an exception is caught by the try...catch block. Sub LaunchWizardExample

Dim params As Object = New Object {  &quot;{0F90E1D0-4999-11D1-B6D1-00A0C90F2744}&quot;,&quot;NewProjectName1&quot;,&quot;NewProjectPath&quot;, &quot;&quot;, False, &quot;&quot;, False } 'The last value is the &quot;Silent&quot; flag where TRUE=No UI, FALSE=UI

Dim res As EnvDTE.wizardResult Dim s As String = DTE.Solution.TemplatePath(VSLangProj.PrjKind.prjKindCSharpProject) Try res = DTE.LaunchWizard(s & &quot;CSharpEXE.vsz&quot;,params) Catch e1 As System.Exception System.Windows.Forms.MessageBox.Show(&quot;Caught an Exception: &quot; + e1.Message) End Try

End Sub For additional information about the Wizard type, search on ContextParams Enum in Books Online.

