Solved

(50 pts) API to find Common directory

Posted on 2000-04-13
8
239 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now