get Common Documents folder in VBS

a 夏天 提交于 2019-12-08 03:20:54

问题


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?


回答1:


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



回答2:


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")


来源:https://stackoverflow.com/questions/8731534/get-common-documents-folder-in-vbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!