This worked ok for me in WinXP (not sure it works in all versions of windows).
Option Explicit
Sub testme01()
MsgBox Environ("programfiles")
End Sub
But I searched *scripting* newsgroups and found something that was close to
this:
Option Explicit
Sub testme02()
Dim sPath As String
Dim WSHShell As Object
Set WSHShell = CreateObject("WScript.Shell")
sPath = WSHShell.environment("Process")("ProgramFiles")
If sPath = "" Then
sPath = WSHShell.RegRead _
("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir")
End If
MsgBox sPath
End Sub
It looks like it tries to use the environment variable. If it doesn't find it,
it goes and reads the registry.
cush wrote:
>
> 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.
>
> sPath = WSHShell.SpecialFolders("Programs")
> returns : \Start Menu\Programs
>
> Any clues?
> Also, where can I find the object model for this?
--
Dave Peterson
Bookmarks