Visual Studio Installer: How to Target Windows Public Documents Folder?

前端 未结 2 1343
陌清茗
陌清茗 2021-02-15 17:53

I am creating a desktop app that needs to install an SDF file to the SpecialFolder.CommonDocuments folder (C:\\Users\\Public\\documents in Win 7). In a

相关标签:
2条回答
  • 2021-02-15 18:41

    I figured this one out and documented it for internal purposes. So, I'll just reprint that writeup here:

    Visual Studio deployment projects don't support the CommonDocuments folder directly, but we can add that support by using the Launch Conditions Editor, which has a "Search Target Machine" task. We will use the task to search the Windows registry for the path to the Public Documents folder and assign the result to an installer property (actually a variable) called COMDOCFOLDER. We will then use that variable to set the path to a custom folder in the File System Editor.

    Here are the steps to perform the task. First, open the Launch Conditions Editor in a Visual Studio deployment project:

    Launch Conditions Editor

    Right-click 'Search Target Machine' and select 'Add Registry Search' from the Context menu. A new item will appear (see 1 above). Name it Get Common Documents Folder. In the properties pane (See 2 above), set the 'Property' property (the name of our variable) to COMDOCFOLDER, set the 'Root' property (the Registry root key to search) to vsdrrHKLM, and set the 'RegKey' property (The Registry key to find) to SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders. Notice that we omitted the root key from the 'RegKey' Property. Finally, set the 'Value' property (The name of the value we are searching for within the registry key) to Common Documents. The COMDOCFOLDER variable will now hold the path to the Public Documents folder.

    Next, go to the File System Editor in the Visual Studio deployment project:

    File System Editor

    Right-click 'File System on Target Machine' and select 'Add Special Folder > Custom Folder' from the context menu. A new item will appear (see 1 above). Rename the item Common Documents. In the properties pane (See 2 above), set the 'Property' property to COMDOCFOLDER. I set the 'DefaultLocation' property to the hard-coded value of the CommonDocuments folder for Windows Vista and later; this value would only be used if the COMDOCFOLDER property returned a null value, which shouldn't happen. The installer now has a Common Documents folder that points to the Public Documents folder, as specified in the Windows Registry.

    There is more information in this Microsoft Support How-To.

    0 讨论(0)
  • 2021-02-15 18:48

    The answer of David Veeneman is great! Helped a lot. A little correction:

    Right-click 'File System on Target Machine' and select 'Add Special Folder > Custom Folder' from the context menu. A new item will appear (see 1 above). Rename the item Common Documents. In the properties pane (See 2 above), set the 'Property' property to

    [COMDOCFOLDER]

    Those square brackets are necessary, otherwise you'll receive exception while executing the installer.

    0 讨论(0)
提交回复
热议问题