powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Определить, на каком диске папка "Program Files"
6 сообщений из 6, страница 1 из 1
Определить, на каком диске папка "Program Files"
    #34742420
у-чен-ик
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Как программно определить, на каком диске находится системная папка "Program Files". Заранее благодарен
...
Рейтинг: 0 / 0
Определить, на каком диске папка "Program Files"
    #34743269
Фотография Worobjoff
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
В FSO есть лишь три стандартных папки: Windows, System32, Temp
...
Рейтинг: 0 / 0
Определить, на каком диске папка "Program Files"
    #34743649
alex1910
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Папок "Program Files" может быть столько, сколько логических дисков, если располагать их в корне диска. А если они будут внутри других папок, то еще больше. Так что определять программно местоположение этой папки, по-моему, смысла нет.
...
Рейтинг: 0 / 0
Определить, на каком диске папка "Program Files"
    #34743692
LeonM
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ищы, ищы...
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
Option Explicit

Private Enum CSIDL                  'CSIDL values provide a unique system-independent way
                                    'to identify special folders used frequently by applications,
                                    'but which may not have the same name or location on any given system.
    CSIDL_FLAG_CREATE = &H8000      'V5.0. Combined with any of the following CSIDLs to force the creation
                                    'of the associated folder.
    CSIDL_ADMINTOOLS = &H30         'V5.0. The file system directory to store administrative tools
                                    'for an individual user.
                                    'The Microsoft Management Console (MMC) will save customized consoles
                                    'to this directory, and it will roam with the user.
    CSIDL_ALTSTARTUP = &H1D         'The file system directory that corresponds to the user's
                                    'nonlocalized Startup program group.
    CSIDL_APPDATA = &H1A            'V4.71. The file system directory that serves as a common repository
                                    'for application-specific data. A typical path is
                                    'C:\Documents and Settings\username\Application Data.
                                    'This CSIDL is supported by the redistributable Shfolder.dll for systems
                                    'that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed.
    CSIDL_BITBUCKET = &HA           'The virtual folder containing the objects in the user's Recycle Bin.
    CSIDL_CDBURN_AREA = &H3B        'V6.0. The file system directory acting as a staging area
                                    'for files waiting to be written to CD. A typical path is
                                    'C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning.
    CSIDL_COMMON_ADMINTOOLS = &H2F  'V 5.0. The file system directory containing administrative tools
                                    'for all users of the computer.
    CSIDL_COMMON_ALTSTARTUP = &H1E  'The file system directory that corresponds to the nonlocalized
                                    'Startup program group for all users.
                                    'Valid only for Microsoft Windows NT systems.
    CSIDL_COMMON_APPDATA = &H23     'V 5.0. The file system directory containing application data
                                    'for all users. A typical path is
                                    'C:\Documents and Settings\All Users\Application Data.
    CSIDL_COMMON_DESKTOPDIRECTORY = &H19    'The file system directory that contains
                                    'files and folders that appear on the desktop for all users.
                                    'A typical path is C:\Documents and Settings\All Users\Desktop.
                                    'Valid only for Windows NT systems.
    CSIDL_COMMON_DOCUMENTS = &H2E   'The file system directory that contains documents
                                    'that are common to all users. A typical paths is
                                    'C:\Documents and Settings\All Users\Documents.
                                    'Valid for Windows NT systems and Microsoft Windows 95 and Windows 98
                                    'systems with Shfolder.dll installed.
    CSIDL_COMMON_FAVORITES = &H1F   'The file system directory that serves as a common repository
                                    'for favorite items common to all users. Valid only for Windows NT systems.
    CSIDL_COMMON_MUSIC = &H35       'V 6.0. The file system directory that serves as a repository
                                    'for music files common to all users. A typical path is
                                    'C:\Documents and Settings\All Users\Documents\My Music.
    CSIDL_COMMON_PICTURES = &H36    'V 6.0. The file system directory that serves as a repository
                                    'for image files common to all users. A typical path is
                                    'C:\Documents and Settings\All Users\Documents\My Pictures.
    CSIDL_COMMON_PROGRAMS = &H17    'The 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.
    CSIDL_COMMON_STARTMENU = &H16   'The file system directory that contains the programs and folders
                                    'that appear on the Start menu for all users. A typical path is
                                    'C:\Documents and Settings\All Users\Start Menu.
                                    'Valid only for Windows NT systems.
    CSIDL_COMMON_STARTUP = &H18     'The file system directory that contains the programs that appear
                                    'in the Startup folder for all users. A typical path is
                                    'C:\Documents and Settings\All Users\Start Menu\Programs\Startup.
                                    'Valid only for Windows NT systems.
    CSIDL_COMMON_TEMPLATES = &H2D   'The file system directory that contains the templates that are
                                    'available to all users. A typical path is
                                    'C:\Documents and Settings\All Users\Templates.
                                    'Valid only for Windows NT systems.
    CSIDL_COMMON_VIDEO = &H37       'V 6.0. The file system directory that serves as a repository
                                    'for video files common to all users. A typical path is
                                    'C:\Documents and Settings\All Users\Documents\My Videos.
    CSIDL_COMPUTERSNEARME = &H3D    'The folder representing other machines in your workgroup.
    CSIDL_CONNECTIONS = &H31        'The virtual folder representing Network Connections,
                                    'containing network and dial-up connections.
    CSIDL_CONTROLS = &H3            'The virtual folder containing icons for the Control Panel applications.
    CSIDL_COOKIES = &H21            'The file system directory that serves as a common repository for
                                    'Internet cookies. A typical path is
                                    'C:\Documents and Settings\username\Cookies.
    CSIDL_DESKTOP = &H0             'The virtual folder representing the Windows desktop, the root of the namespace.
    CSIDL_DESKTOPDIRECTORY = &H10   'The file system directory used to physically store file objects
                                    'on the desktop (not to be confused with the desktop folder itself).
                                    'A typical path is C:\Documents and Settings\username\Desktop.
    CSIDL_DRIVES = &H11             'The virtual folder representing My Computer, containing everything
                                    'on the local computer: storage devices, printers, and Control Panel.
                                    'The folder may also contain mapped network drives.
    CSIDL_FAVORITES = &H6           'The file system directory that serves as a common repository
                                    'for the user's favorite items. A typical path is
                                    'C:\Documents and Settings\username\Favorites.
    CSIDL_FONTS = &H14              'A virtual folder containing fonts. A typical path is C:\Windows\Fonts.
    CSIDL_HISTORY = &H22            'The file system directory that serves as a common repository
                                    'for Internet history items.
    CSIDL_INTERNET = &H1            'A virtual folder representing the Internet.
    CSIDL_INTERNET_CACHE = &H20     'V 4.72. The file system directory that serves as a common repository
                                    'for temporary Internet files. A typical path is
                                    'C:\Documents and Settings\username\Local Settings\Temporary Internet Files.
    CSIDL_LOCAL_APPDATA = &H1C      'V 5.0. The file system directory that serves as a data repository
                                    'for local (nonroaming) applications. A typical path is
                                    'C:\Documents and Settings\username\Local Settings\Application Data.
    CSIDL_MYDOCUMENTS = &HC         'V 6.0. The virtual folder representing the My Documents desktop item.
    CSIDL_MYMUSIC = &HD             'The file system directory that serves as a common repository
                                    'for music files. A typical path is
                                    'C:\Documents and Settings\User\My Documents\My Music.
    CSIDL_MYPICTURES = &H27         'V 5.0. The file system directory that serves as a common repository
                                    'for image files. A typical path is
                                    'C:\Documents and Settings\username\My Documents\My Pictures.
    CSIDL_MYVIDEO = &HE             'V 6.0. The file system directory that serves as a common repository
                                    'for video files. A typical path is
                                    'C:\Documents and Settings\username\My Documents\My Videos.
    CSIDL_NETHOOD = &H13            'A file system directory containing the link objects that
                                    'may exist in the My Network Places virtual folder.
                                    'It is not the same as CSIDL_NETWORK, which represents the network
                                    'namespace root. A typical path is C:\Documents and Settings\username\NetHood.
    CSIDL_NETWORK = &H12            'A virtual folder representing Network Neighborhood,
                                    'the root of the network namespace hierarchy.
    CSIDL_PERSONAL = &H5            'V 6.0. The virtual folder representing the My Documents desktop item.
                                    'This is equivalent to CSIDL_MYDOCUMENTS.
                                    'Previous to V 6.0. The file system directory usedto physically store
                                    'a user's common repository of documents. A typical path is
                                    'C:\Documents and Settings\username\My Documents. This should be distinguished
                                    'from the virtual My Documents folder in the namespace.
                                    'To access that virtual folder, use SHGetFolderLocation, which returns
                                    'the ITEMIDLIST for the virtual location, or refer to the technique
                                    'described in Managing the File System.
    CSIDL_PHOTOALBUMS = &H45        '(preliminary) Windows Vista and later. The virtual folder used to
                                    'store photo albums, typically username\My Pictures\Photo Albums.
    CSIDL_PLAYLISTS = &H3F          '(preliminary) Windows Vista and later. The virtual folder used to
                                    'store play albums, typically username\My Music\Playlists.
    CSIDL_PRINTERS = &H4            'The virtual folder containing installed printers.
    CSIDL_PRINTHOOD = &H1B          'The file system directory that contains the link objects
                                    'that can exist in the Printers virtual folder. A typical path is
                                    'C:\Documents and Settings\username\PrintHood.
    CSIDL_PROFILE = &H28            'V 5.0. The user's profile folder. A typical path is
                                    'C:\Documents and Settings\username. Applications should not create
                                    'files or folders at this level; they should put their data under
                                    'the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.
    CSIDL_PROGRAM_FILES = &H26      'V 5.0. The Program Files folder. A typical path is C:\Program Files.
    CSIDL_PROGRAM_FILES_COMMON = &H2B   'V 5.0. A folder for components that are shared across applications.
                                    'A typical path is C:\Program Files\Common. Valid only for
                                    'Windows NT, 2000, and XP systems. Not valid for Windows Me.
    CSIDL_PROGRAMS = &H2            'The file system directory that contains the user's program groups
                                    '(which are themselves file system directories). A typical path is
                                    'C:\Documents and Settings\username\Start Menu\Programs.
    CSIDL_RECENT = &H8              'The file system directory that contains shortcuts to the
                                    'user's most recently used documents. A typical path is
                                    'C:\Documents and Settings\username\My Recent Documents.
                                    'To create a shortcut in this folder, use SHAddToRecentDocs.
                                    'In addition to creating the shortcut, this function updates the
                                    'Shell's list of recent documents and adds the shortcut to the
                                    'My Recent Documents submenu of the Start menu.
    CSIDL_RESOURCES = &H38          '
    CSIDL_SAMPLE_MUSIC = &H40       '(preliminary) Windows Vista and later. The file system directory
                                    'that contains sample music. A typical path is
                                    'C:\Documents and Settings\username\My Documents\My Music\Sample Music.
    CSIDL_SAMPLE_PLAYLISTS = &H41   '(preliminary) Windows Vista and later. The file system directory
                                    'that contains sample playlists. A typical path is
                                    'C:\Documents and Settings\username\My Documents\My Music\Sample Playlists.
    CSIDL_SAMPLE_PICTURES = &H42    '(preliminary) Windows Vista and later. The file system directory that
                                    'contains sample pictures. A typical path is
                                    'C:\Documents and Settings\username\My Documents\My Pictures\Sample Pictures.
    CSIDL_SAMPLE_VIDEOS = &H43      'preliminary) Windows Vista and later. The file system directory
                                    'that contains sample videos. A typical path is
                                    'C:\Documents and Settings\username\My Documents\My Videos\Sample Videos.
    CSIDL_SENDTO = &H9              'The file system directory that contains Send To menu items.
                                    'A typical path is C:\Documents and Settings\username\SendTo.
    CSIDL_STARTMENU = &HB           'The file system directory containing Start menu items. A typical path is
                                    'C:\Documents and Settings\username\Start Menu.
    CSIDL_STARTUP = &H7             'The file system directory that corresponds to the user's Startup
                                    'program group. The system starts these programs whenever any user logs
                                    'onto Windows NT or starts Windows 95. A typical path is
                                    'C:\Documents and Settings\username\Start Menu\Programs\Startup.
    CSIDL_SYSTEM = &H25             'V 5.0. The Windows System folder. A typical path is C:\Windows\System32.
    CSIDL_TEMPLATES = &H15          'The file system directory that serves as a common repository
                                    'for document templates. A typical path is C:\Documents and Settings\username\Templates.
    CSIDL_WINDOWS = &H24            'V 5.0. The Windows directory or SYSROOT. This corresponds to
                                    'the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\Windows.
End Enum

'Private Declare Function SHGetFolderPath Lib "shell32" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, _
'    ByVal nFolder As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal pszPath) As Long
'Private Declare Function SHGetFolderLocation Lib "shell32" (ByVal hwndOwner As Long, ByVal nFolder As Long, _
'    ByVal hToken As Long, ByVal dwReserved As Long, ByVal ppidl As Long) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32" (ByVal hwndOwner As Long, _
    ByVal hToken As Long, ByVal ppidl As Long) As Long
Private Declare Function SHGetSpecialFolderPath Lib "shell32" Alias "SHGetSpecialFolderPathW" (ByVal hwndOwner As Long, _
    ByVal lpszPath As Long, ByVal nFolder As Long, ByVal fCreate As Long) As Boolean

Private Const MAX_PATH As Long =  260 
Private Const SHGFP_TYPE_CURRENT As Long =  0     'current value for user, verify it exists
Private Const SHGFP_TYPE_DEFAULT As Long =  1     'default value, may not exist

Private m_hwnd As Long
Private m_buf As Long
Private m_str As String

Private Sub Class_Initialize()
    m_hwnd = Application.hWnd
    m_str = String(MAX_PATH, Chr( 0 ))
    m_buf = StrPtr(m_str)
End Sub

Private Function FolderPath(ByVal fl As CSIDL) As String
    Dim n As Integer
    Class_Initialize
    n =  1 
    FolderPath = ""
    If SHGetSpecialFolderPath(m_hwnd, m_buf, fl,  0 ) Then
        While Mid(m_str, n,  1 ) <> Chr( 0 )
            FolderPath = FolderPath & Mid(m_str, n,  1 )
            n = n +  1 
        Wend
    End If
End Function

Public Function MyDesktop() As String
    MyDesktop = FolderPath(CSIDL_DESKTOPDIRECTORY)
End Function
Public Function MyDocuments() As String
    MyDocuments = FolderPath(CSIDL_PERSONAL)
End Function
Public Function MyStartmenu() As String
    MyStartmenu = FolderPath(CSIDL_STARTMENU)
End Function
Public Function MyFavorites() As String
    MyFavorites = FolderPath(CSIDL_FAVORITES)
End Function
Public Function MyRecent() As String
    MyRecent = FolderPath(CSIDL_RECENT)
End Function
Public Function CommonDocuments() As String
    CommonDocuments = FolderPath(CSIDL_COMMON_DOCUMENTS)
End Function
Public Function CommonStartmenu() As String
    CommonStartmenu = FolderPath(CSIDL_COMMON_STARTMENU)
End Function
Public Function System() As String
    System = FolderPath(CSIDL_SYSTEM)
End Function
Public Function WinFolder() As String
    WinFolder = FolderPath(CSIDL_WINDOWS)
End Function
Public Function InternetTemporarty() As String
    InternetTemporarty = FolderPath(CSIDL_INTERNET_CACHE)
End Function
Public Function ProgramFiles() As String
    ProgramFiles = FolderPath(CSIDL_PROGRAM_FILES)
End Function

...
Рейтинг: 0 / 0
Определить, на каком диске папка "Program Files"
    #34743722
Фотография HandKot
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
environ("ProgramFiles")

I Have Nine Lives You Have One Only
THINK!
...
Рейтинг: 0 / 0
Определить, на каком диске папка "Program Files"
    #34743750
Фотография klen_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
как один из вариантов
и системная и не системная
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Dim FSO As FileSystemObject                ' (объект) MicroSoft Scripting Runtime
Set FSO = New FileSystemObject
  
Dim drv As Drive
Dim pfl As String, disk As String
 
For Each drv In FSO.Drives
    pfl = drv.DriveLetter & ":\Program Files"
    If FSO.FolderExists(pfl) Then
        disk = disk & pfl & Chr( 13 )
    End If
Next
Set FSO = Nothing

MsgBox disk
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Определить, на каком диске папка "Program Files"
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]