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
Solved

(50 pts) API to find Common directory

Posted on 2000-04-13
8
241 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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 50 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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