Solved

(50 pts) API to find Common directory

Posted on 2000-04-13
8
240 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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