Как узнать путь к директории Program Files?
Ведь на версиях Windows (испанская, немецкая, и др.) название у этой директории другое.
Как узнать путь к этой директории?
Environ("ProgramFiles")
'В форму
Option Explicit
Private Sub Form_Load()
Debug.Print ReadCurrentVersion("ProgramFilesDir")
End Sub
'В модуль
Option Explicit
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByRef lpData As Any, ByRef lpcbData As Long) As Long
Public Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const REG_SZ = 1
Public Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Public Const KEY_QUERY_VALUE As Long = &H1
Public Const KEY_SET_VALUE As Long = &H2
Public Const KEY_CREATE_SUB_KEY As Long = &H4
Public Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
Public Const KEY_NOTIFY As Long = &H10
Public Const KEY_CREATE_LINK As Long = &H20
Public Const SYNCHRONIZE As Long = &H100000
Public Const KEY_ALL_ACCESS As Long = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Public Const RegCVPath9x = "SOFTWARE\Microsoft\Windows\CurrentVersion"
Public Const RegCVPathNT = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
Public SA As SECURITY_ATTRIBUTES
Public Function ReadCurrentVersion(ByVal strRegKeyName As String) As String
Dim Result As Long
Dim lBuffSize As Long
Dim UCVRegPath As String
Dim intRetPos As Integer
UCVRegPath = RegCVPath9x
Start:
RegOpenKeyEx HKEY_LOCAL_MACHINE, UCVRegPath, 0, KEY_ALL_ACCESS, Result
RegQueryValueEx Result, strRegKeyName, 0, 0, ByVal ReadCurrentVersion, lBuffSize
If lBuffSize > 0 Then ReadCurrentVersion = Space$(lBuffSize)
RegQueryValueEx Result, strRegKeyName, 0, 0, ByVal ReadCurrentVersion, Len(ReadCurrentVersion)
RegCloseKey Result
If ReadCurrentVersion = vbNullString And UCVRegPath <> RegCVPathNT Then
UCVRegPath = RegCVPathNT
GoTo Start:
End If
If ReadCurrentVersion = vbNullString Then Exit Function
intRetPos = InStr(ReadCurrentVersion, vbNullChar)
ReadCurrentVersion = Left$(ReadCurrentVersion, intRetPos - 1)
End Function
Private Declare Function SHGetFolderPath Lib "shell32.dll" Alias "SHGetFolderPathA" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal pszPath As String) As Long
Const CSIDL_PROGRAM_FILES As Long = &H26
Private Sub Form_Load()
Dim s As String, i As Long
s = String(256, " ")
i = SHGetFolderPath(0, CSIDL_PROGRAM_FILES, 0, 0, s)
s = Left(s, InStr(s, vbNullChar) - 1)
End Sub
Сейчас этот форум просматривают: Google-бот и гости: 184