Visual Basic, .NET, ASP, VBA, VBScript
 
  Библиотека кодов  
  Работа с WINDOWS  
     
  Местоположение системных папок  
  Данный пример покажет в какие директории проинсталированы Windows, а также папка расположения системных файлов и папка временных файлов.
'Вариант 1

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Resize()
Dim sDir As String, sTemp As String * 256
nSize = GetWindowsDirectory(sTemp, 255): pWindows = Left(sTemp, nSize)
Print "Windows = " & pWindows
nSize = GetSystemDirectory(sTemp, 255): pSystem = Left(sTemp, nSize)
Print "System = " & pSystem
nSize = GetTempPath(255, sTemp): pTemp = Left(sTemp, nSize)
Print "Temp = " & pTemp
End Sub


'Вариант 2

'Расположение папки System (в виде функции)
'Расположение папки Windows (в виде функции)
Private Declare Function GetSystemDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetWindowsDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function GetSystemDirectory() As String
Dim s As String
Dim i As Integer
i = GetSystemDirectoryA("", 0)
s = Space(i)
Call GetSystemDirectoryA(s, i)
s = Left$(s, i - 1)
GetSystemDirectory = s
Dim s As String
Dim i As Integer
End Function
Public Function GetWindowsDirectory() As String
Dim s As String
Dim i As Integer
i = GetWindowsDirectoryA("", 0)
s = Space(i)
Call GetWindowsDirectoryA(s, i)
s = Left$(s, i - 1)
GetWindowsDirectory = s
End Function

Private Sub Form_Load()
MsgBox GetSystemDirectory
MsgBox GetWindowsDirectory
End Sub


'Вариант 3

Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nSize As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Enum SystemDirs
dirWindows = 0
dirSystem = 1
dirTemp = 2
End Enum
Function GetSystemFolders(func As SystemDirs)
Dim r, nSize As Long, tmp As String
tmp = Space$(256): nSize = Len(tmp)
Select Case func
Case 0
r = GetWindowsDirectory(tmp, nSize): GetSystemFolders = TrimNull(tmp)
Case 1
r = GetSystemDirectory(tmp, nSize): GetSystemFolders = TrimNull(tmp)
Case 2
r = GetTempPath(nSize, tmp): GetSystemFolders = TrimNull(tmp)
End Select
End Function
Private Function TrimNull(Item As String)
Dim pos As Integer: pos = InStr(Item, Chr$(0))
If pos Then
TrimNull = Left$(Item, pos - 1)
Else: TrimNull = Item
End If
End Function

Private Sub Command1_Click()
For i = 0 To 2
MsgBox GetSystemFolders(Str(i))
Next
End Sub
 
     
  VBNet online (всего: 52050)  
 

Логин:

Пароль:

Регистрация, забыли пароль?


В чате сейчас человек
 
     
  VBNet рекомендует  
   
     
  Лучшие материалы  
 
ActiveX контролы (112)
Hitman74_Library (36119)
WindowsXPControls (20739)
FlexGridPlus (19374)
DSMAniGifControl (18295)
FreeButton (15157)
Примеры кода (546)
Parol (18027)
Passworder (9299)
Screen saver (7654)
Kerish AI (5817)
Folder_L (5768)
Статьи по VB (136)
Мое второе впечатление... (11236)
VB .NET: дорога в будущее (11161)
Основы SQL (9225)
Сообщения Windows в Vi... (8788)
Классовая теория прогр... (8619)
 
     
Техническая поддержка MTW-хостинг | © Copyright 2002-2011 VBNet.RU | Пишите нам