문제

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 Property

commonAppDataFolder = session.Property("CommonAppDataFolder")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top