?
Solved

(50 pts) API to find Common directory

Posted on 2000-04-13
8
Medium Priority
?
250 Views
Last Modified: 2010-05-02
There's a Windows API to find the Windows, Windows\System, and Windows\Temp directory... but I don't know of any API to find the Program Files\Common directory.  

I didn't need to know this until I found out that Microsoft went and changed how Windows works!!  STUPID!  Anyways... I need sample code on how to do it along with declarations/constants/types used in sample code.

Thanks,

HATCHET
0
Comment
Question by:HATCHET
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2714414
http://www.mvps.org/vbnet/code/shell/csidl.htm
http://www.mvps.org/vbnet/code/shell/shpathidlist.htm

two links with the same idea...hope one of em points you to what you need
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2714758
Put a command button on the form.
Msgbox SystemPath(CSIDL_PROGRAMS) -- use the directory type


Option Explicit

Private Declare Function SHGetSpecialFolderLocation Lib "Shell32.DLL" (ByVal hWndOwner As Long, ByVal SHFolder As Long, idl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32.DLL" (ByVal idl As Long, ByVal Path As String) As Long
Private Declare Function GetDesktopWindow Lib "User32.DLL" () As Long

' Enumeration for special directory type
Public Enum SystemFolder
   CSIDL_DESKTOP = 0
   CSIDL_INTERNET = 1
   CSIDL_PROGRAMS = 2
   CSIDL_CONTROLS = 3
   CSIDL_PRINTERS = 4
   CSIDL_PERSONAL = 5
   CSIDL_FAVORITES = 6
   CSIDL_STARTUP = 7
   CSIDL_RECENT = 8
   CSIDL_SENDTO = 9
   CSIDL_BITBUCKET = 10
   CSIDL_STARTMENU = 11
   CSIDL_DESKTOPDIRECTORY = 16
   CSIDL_DRIVES = 17
   CSIDL_NETWORK = 18
   CSIDL_NETHOOD = 19
   CSIDL_FONTS = 20
   CSIDL_TEMPLATES = 21
   CSIDL_COMMON_STARTMENU = 22
   CSIDL_COMMON_PROGRAMS = 23
   CSIDL_COMMON_STARTUP = 24
   CSIDL_COMMON_DESKTOPDIRECTORY = 25
   CSIDL_APPDATA = 26
   CSIDL_PRINTHOOD = 27
   CSIDL_ALTSTARTUP = 29
   CSIDL_COMMON_ALTSTARTUP = 30
   CSIDL_COMMON_FAVORITES = 31
   CSIDL_INTERNET_CACHE = 32
   CSIDL_COOKIES = 33
   CSIDL_HISTORY = 34
   End Enum
   
Public Function SystemPath(ByVal PathID As SystemFolder) As String
' Call to get the directory path of a special directory (any in enum list)
Dim lngIDL As Long
Dim strBuff As String
strBuff = Space$(1024)
Dim n As Long
n = SHGetSpecialFolderLocation(GetDesktopWindow(), PathID, lngIDL)
If n Then Exit Function
n = SHGetPathFromIDList(lngIDL, strBuff)
If n > 0 Then
   n = InStr(strBuff, Chr$(0)) - 1
   strBuff = Left$(strBuff, n)
   If Right$(strBuff, 1) <> "\" Then strBuff = strBuff & "\"
   SystemPath = strBuff
   End If
End Function

Private Sub Command1_Click()
MsgBox SystemPath(CSIDL_COMMON_PROGRAMS)
End Sub
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2714762
Forget to tell you something.
Just change the directory type by using the number. For instance, use MsgBox SystemPath(34) for History folder.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:HATCHET
ID: 2718606
AzraSound & Ruchi,

The SHGetSpecialFolderLocation is NOT the way to get the path to C:\Program Files\Common.  It's a great way to get the paths to a lot of other special paths... adn that's usefull, but it doesn't answer my question.  I'm sorry.

Here's what Microsoft's documentation says about the CSIDL_COMMON_PROGRAMS flag when passed to this function:

"File system directory that contains the directories for the common program groups that appear on the Start menu for all users.  A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT® systems."


Any other suggestions?

HATCHET
0
 
LVL 3

Author Comment

by:HATCHET
ID: 2720713
I did some researching into this and in Windows 2000, there's a parameter that you can pass this function that will return the Windows, Windows\System, Program Files, and Program Files\Common directories.  That doesn't help me since I'm programming for Windows 95/98/NT.  There's got to be another way to do this.

HATCHET
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2721718
CSIDL_PROGRAM_FILES_COMMON - Version 5.0. A folder for components that are shared across applications. A common path is C:\Program Files\Common. Valid only for Windows NT and Windows® 2000 systems.
CSIDL_PROGRAM_FILES_COMMONX86 - Version 5.0. Program Files folder that is common to all users for x86 applications on RISC systems. A common path is C:\Program Files (x86)\Common.


still looking...
0
 
LVL 3

Accepted Solution

by:
HATCHET earned 200 total points
ID: 2735272
Well, I got the code to use the  SHGetSpecialFolderLocation and SHGetPathFromIDList API's to get the Program Files directory, but you need Windows 2000 to do it.  That doesn't work for me.  I need it for Win 9x / NT / 2000.

What I did find that is a reliable way to get this information from any system is getting it directly from the Windows Registry (which is where the API's get it I believe).  The following registry locations will give you the following directories:

- Windows Directory (C:\WINDOWS)
   (Add "\System" to the end of this to get the WinSys Dir)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\SystemRoot

- Common Directory (C:\Program Files\Common Files):
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\CommonFilesDir

- Program Files Directory (C:\Program Files)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir

- Program Files Path (C:\Program Files)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProgramFilesPath

- .INF Directory (C:\WINDOWS\INF)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\DevicePath

- Multimedia Directory (C:\WINDOWS\Media)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\MediaPath

- Internet Explorer "Active Desktop" Wallpaper Directory
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WallPaperDir
0
 
LVL 3

Expert Comment

by:darinw
ID: 2736876
I am accepting one of HATCHET's comments as an answer to move this question to the PAQ.
 
darinw
Customer Service
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question