HOW TO: Retrieve a Value from the Registry and Then Use the Value in a Setup Project in Visual Studio .NET (827026)
The information in this article applies to:
- Microsoft Windows Installer
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SUMMARYThis step-by-step article describes how to retrieve a
value from the registry. This article also describes how to use this value in a setup
project that you create by using Visual Studio .NET. The examples in this article describe how to retrieve the MediaPath value for your
computer from the registry, and then install your application to a
folder that is located in the folder that your MediaPath value specifies. back to the topRequirementsThe following list outlines the recommended hardware, software,
network infrastructure, and service packs that you need:
- Microsoft Windows 2000, Microsoft Windows XP, or Microsoft
Windows Server 2003
- Microsoft Visual Studio .NET
This article assumes that you are familiar with the following
topic:
- Visual Studio .NET Setup Projects
back to the topCreate a Setup Project- Start Visual Studio .NET.
- On the File menu, point to
New, and then click Project.
- Under Project Types, click
Setup and Deployment Projects.
- Under Templates, click
Setup Project.
- In the Name text box, type
MyApp.
- Click OK.
back to the topAdd a File to Your Setup Project- Create a file that is named Readme.txt. To do this, follow these steps:
- Start a text editor (such as Notepad).
- Type the following text in
the text editor:
This application is installed in a folder that
depends on a value that is read from the system
registry. - On the File menu, click
Save.
- In the Save As dialog box, locate the
folder where you created the MyApp project in the "Create a Setup Project" section of this
article.
- In the File name text box, type
Readme.txt.
- Click
Save.
- Switch to Visual Studio .NET.
- On the Project menu, point to
Add, and then click File.
- In the Add Files dialog box, locate and
then click the Readme.txt file that you created in step 1.
- Click
Open.
The Readme.txt file is added to
the MyApp project. back to the topRetrieve a Value from the RegistryThe MediaPath value for your computer is located under the
following registry subkey: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion You
can retrieve this value by using a launch condition. To do this, follow these steps:
- In Visual Studio .NET, point to
Editor on the View menu, and then click Launch
Conditions.
- In the Launch Conditions Editor, click Search
Target Machine.
- On the Action menu, click Add
Registry Search.
By default, Search for
RegistryEntry1 is added. - On the View menu, click Properties
Window to select the Properties window for the registry search that you created
in step 3.
- Change the Name property value to
Search for MediaPath.
- Change the Property property value to
MEDIA_PATH.
When you run the setup project, the MediaPath registry value is retrieved to your MEDIA_PATH
property. - To search HKEY_LOCAL_MACHINE in the registry, click
the Root property, and then click
vsdrrHKLM in the drop-down list box for the property value.
- To search the SOFTWARE\Microsoft\Windows\CurrentVersion
subkey, type
SOFTWARE\Microsoft\Windows\CurrentVersion in the RegKey property value text box.
- To search for the MediaPath value, type
MediaPath in the Value property value text box.
back to the topUse the Retrieved Value to Change Your Installation PathTo change your installation path based on the value of your
MediaPath property, change the value of the DefaultLocation property for your application
folder. To do this, follow these steps: - Switch to the File System Editor.
- Under File System on Target Machine, click Application Folder.
- On the View menu, click Properties
Window to select the Properties window for Application
Folder.
- To change your installation path based on the value of your
MediaPath property, change the DefaultLocation property value to
[MEDIA_PATH]\MyApp.
When you run the setup project, this value causes Setup to install your
application to the MyApp folder in your Media folder. For
example, if your MediaPath value is C:\WINDOWS\Media, Setup installs MyApp to the C:\WINDOWS\Media\MyApp folder.
Note Notice that MEDIA_PATH is enclosed in square brackets in the property value. When you reference a property in any property other than a
Condition property, enclose your original property
in square brackets. back to the topVerify That Your Application Works- On the Build menu, click Build
Solution.
- Start Windows Explorer.
- Locate the Setup.exe file that
you built in step 1.
Setup.exe is located in a folder named Debug. The Debug folder is located in the MyApp folder
where you created your MyApp setup project in the
"Create a Setup Project" section of
this article. - Run the Setup.exe file.
- On the Welcome to the MyApp Setup Wizard
page, click Next.
- On the Select Installation Folder page,
notice that the Folder text box contains your customized
installation path. For example, if your MediaPath value is C:\WINDOWS\Media,
the Folder text box contains
C:\WINDOWS\Media\MyApp\. Click Next.
- On the
Confirm Installation page, click Next to
install MyApp.
- On the Installation Complete page, click
Close to quit your installation.
- In Windows Explorer, locate the folder where you installed MyApp.
Note The path of this folder appeared in the
Folder text box in step 6.
Notice that the
Readme.txt file is located in this folder. - Open the Readme.txt file.
Notice that the
Readme.txt file contains the text that you typed in step 1b of the
"Add a File to Your Setup Project"
section of this article. back to the
topREFERENCES For more information, visit the following Microsoft
Developer Network (MSDN) Web sites: back to the
top
Modification Type: | Minor | Last Reviewed: | 5/23/2005 |
---|
Keywords: | kbRegistry kbSysSettings kbAppSetup kbPDWizard kbIDEProject kbDeployment kbsetup kbProgramming kbHOWTOmaster KB827026 kbAudDeveloper |
---|
|
|
©2004 Microsoft Corporation. All rights reserved.
|
|