Determine and obtain the Visual Studio installation path

Source: Internet
Author: User

Recently, it was found that it is quite convenient to use vs to process XML files. The key is that the shortcut keys have been used very well. In addition to not highlighting the notepad ++ feature with the same string, the syntax check is good, so you can use vs as the default XML text editor in the tool.

 

After studying the registry key for a long time, it was found that it was not so easy to judge whether vs was installed. At least it was not that simple.

1. The vs registration item is in HKEY_CURRENT_USER/software/Microsoft/visualstudio/. If vs8 and vs9 are installed at the same time, there are two downgrading items: 8.0, 9.0;

Note: Do not look for it from HKEY_LOCAL_MACHINE, you will find a lot of versions, vs3-vs9 has.

2. The installation location of Vs, which is not so reliable, can only find a last location written to the Registry. When vs is installed,

Hkey_local_machile/software/Microsoft/CurrentVersion/APP paths/devenv. EXE. The default value is the installation location of vs. However, if vs8 is installed first and vs9 is installed, this option is changed to the installation directory of vs9.

3. maybe you will say that it is okay to enable VS solution normally. In Windows, find the right option to enable vs. In fact, there is another thing in C: /program files/common files/Microsoft shared/msenv/vslauncher.exe. This learning name is Visual Studio version selector, which is used to obtain the correct vs version. It should maintain the Visual Studio version and location information, but unfortunately vslauncher does not store the relevant information in the Registry-this is a headache ....

 

...

 

There seems to be nothing wrong with the above ideas, but it is actually wrong. Have you noticed it...

 

I was wrong from the very beginning, making the subsequent reasoning more and more complex. Step 1 when I see so many versions of HKEY_LOCAL_MACHINE/software/Microsoft/visualstudio/, I think the information in this item is not practical, therefore, if there is no test, the system will ignore it directly, but there is actually a key information in it. Although there are indeed many versions in it, there is no value for those that are not installed, and under the already installed items, you will see installdir -- that is, the installation directory of this version, in this way, OK.

 

When operating the registry, writing registry functions one by one would be dead. I have written the functions many times, but I have forgotten many times that the design of those functions is really unfriendly. But it doesn't matter. We have BCG, where the cbcgpregistry class can be used to easily operate the Registry. Of course, there are many free class libraries like codeproject. In short, never write them by yourself, if you really want to write it, write it comprehensively and publish it to the Internet. It can be reused in the future. Otherwise, it will be boring, because you will soon forget :~ (

 

Cstring pathname; <br/> cbcgpregistry Reg (true, false); // true is critical, specifying Reg under HKEY_LOCAL_MACHINE <br/>. open ("software/Microsoft // visualstudio // 9.0 // setup // vs //" <br/> Reg. read ("environmentpath", pathname );

 

Summary: 1. obtain the number of versions installed by the user under HKEY_CURRENT_USER, for example, 8.0 or 9.0, and then select a version as the default version, find the corresponding version number from HKEY_LOCAL_MACHINE and obtain its address, and then write it into the registry of the tool.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.