Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding a users Program Files (2000)

    I am able to locate a users desktop with the following code:

    Set WSHShell = CreateObject("WScript.Shell")
    sPath = WSHShell.specialfolders("Desktop")

    I need something similar to locate the Program Files, which are not always located at C:Program Files

    I tried:
    Set WSHShell = CreateObject("WScript.Shell")
    sPath = WSHShell.SpecialFolders("Program Files")

    both with and without the space, but it only turned up
    an empty string.
    Any clues?
    Also, where can I find the object model for this?

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    I'm looking in WSH Helpfile and see the following in the special folders list:
    AllUsersDesktop
    AllUsersStartMenu
    AllUsersPrograms
    AllUsersStartup
    Desktop
    Favorites
    Fonts
    MyDocuments
    NetHood
    PrintHood
    Programs
    Recent
    SendTo
    StartMenu
    Startup
    Templates

    I guess it might be "Programs".

    Alan

  3. #3
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    Thanks Alan

    I'll try this
    and where do I find the
    WSH Helpfile ?

  4. #4
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    Alan,

    I tried Programs and AllUsersPrograms

    They yeilded : Start MenuPrograms
    not what I was hoping for.

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    The helpfile can be obtained from Windows Script 5.6 Documentation.

    I'm confused also with the "special folders" names. TweakUI gives a different list from the above. One of them is "Program Files", another "Programs" (the Startup folder you found) and another is "Common Program Files". Hopefully someone can chime in with the definitive answer.

    Alan

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    This page shows the API codes to get at a host of special folders. Program files is one of them.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  7. #7
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    Jan
    Thanks for the reply. I went to the site and copied the entire code into a new wbk standard module.
    I then created the following sub:

    <pre>Private Sub FindProgFilesLoc()
    Dim sPath As String

    sPath = fGetSpecialFolderLocation(CSIDL_PROGRAM_FILES)
    MsgBox sPath

    End Sub</pre>




    When I run it I get a variable not defined on:

    lngRet = apiSHGetSpecialFolderLocation(hWndAccessApp, lngCSIDL, pidl)

    with the <font color=red> <font color=blue>'hWndAccessApp' </font color=blue> </font color=red> highlited.
    I assume this needs a dim statement with a variable pointing to MS xl.
    Since I know very little about using APIs, I'm a little reluctant to experiment.
    Can you tell me how you would set this up.
    Also do the other 2 function arguments need further variable declarations?

    Thanks

  8. #8
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    Alan and Jan

    I found this in another forum. If it is stable it is much simpler and stands alone:

    <pre>Sub GetProgFilesPath()

    Dim sPath As String
    Dim WSHShell As Object
    Set WSHShell = CreateObject("WScript.Shell")

    'This may not work on Windows 9x
    sPath = WSHShell.Environment("Process")("ProgramFiles")

    'if not, look in the Registry
    If sPath = "" Then
    sPath = WSHShell.RegRead _
    ("HKLMSOFTWAREMicrosoftWindowsCurrentVersionProgra mFilesDir")
    End If

    MsgBox sPath

    End Sub</pre>


  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Finding a users Program Files (2000)

    That code is meant for Access. You can replace hWndAccessApp by 0, but although the function will return the location of folders related to my user, it won't return anything for general folders such as Program Files, for me at least. Instead, try

    sPath = Environ("ProgramFiles")

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    Or:

    MsgBox Left(Application.Path, InStr(4, Application.Path, Application.PathSeparator))
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  11. #11
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    That will give you the low level directory where Excel is located. That is not necessarily the default program directory, particularly if you are on a network using a shared Excel program.
    Legare Coleman

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    Correct of course.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  13. #13
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a users Program Files (2000)

    I guess it depends on what you are really trying to find. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Legare Coleman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •