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?
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
Ignoring the fact that VBScript custom actions are very problematic, you can just ask WindowsInstaller for the location of the CommonAppDataFolder.
commonAppDataFolder = session.Property("CommonAppDataFolder")
来源:https://stackoverflow.com/questions/8731534/get-common-documents-folder-in-vbs