Question

To my great chagrin, I must use VBS to write an InstallShield 2010 LE custom action. I have no VBS experience so I'm basically putting together code snippets that I find.

I need to get a hold of the Common Documents folder (CSIDL_COMMON_DOCUMENTS). It's not defined in WScript.Shell.SpecialFolders (although All Users Desktop is). I found some example code that tries to link to a system DLL:

Private Declare Function SHGetFolderPath Lib "shfolder.dll" _
Alias "SHGetFolderPathA" _
    (ByVal hwndOwner As Long, _
    ByVal nFolder As Long, _
    ByVal hToken As Long, _
    ByVal dwReserved As Long, _
    ByVal lpszPath As String) As Long

But when I try to run it in VbsEdit, I get the following error on the first line:

Microsoft VBScript compilation error: Expected end of statement

Any ideas?

Was it helpful?

Solution

Stolen from here

  Const CSIDL_COMMON_DOCUMENTS = &h2e
  Dim objShell : Set objShell = CreateObject("Shell.Application")
  WScript.Echo objShell.Namespace(CSIDL_COMMON_DOCUMENTS).Self.Path

output:

C:\Documents and Settings\All Users\Documents

OTHER TIPS

Ignoring the fact that VBScript custom actions are very problematic, you can just ask WindowsInstaller for the location of the CommonAppDataFolder.

CommonAppDataFolder Property

commonAppDataFolder = session.Property("CommonAppDataFolder")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top