API-Guide писал(а):1.
Description:The GetSystemDirectory function retrieves the path of the Windows system directory. The system directory contains such files as Windows libraries, drivers, and font files.
Declararion:- Код: Выделить всё
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Parameters:· lpBuffer
Points to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named WINDOWS\SYSTEM on drive C, the path of the system directory retrieved by this function is C:\WINDOWS\SYSTEM.
· uSize
Specifies the maximum size of the buffer, in characters. This value should be set to at least MAX_PATH.
Return Values:If the function succeeds, the return value is the length, in characters, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Sample:- Код: Выделить всё
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
'Show the windows directory
MsgBox "Windows System directory: " + sSave
End Sub
2.
Descrption:The GetWindowsDirectory function retrieves the path of the Windows directory. The Windows directory contains such files as Windows-based applications, initialization files, and Help files.
Declaration:- Код: Выделить всё
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Parameters:· lpBuffer
Points to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named WINDOWS on drive C, the path of the Windows directory retrieved by this function is C:\WINDOWS. If Windows was installed in the root directory of drive C, the path retrieved is C:\.
· uSize
Specifies the maximum size, in characters, of the buffer specified by the lpBuffer parameter. This value should be set to at least MAX_PATH to allow sufficient room in the buffer for the path.
Return Values:If the function succeeds, the return value is the length, in characters, of the string copied to the buffer, not including the terminating null character.
If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Sample:- Код: Выделить всё
'This project needs a PictureBox, called 'Picture1'
'In general section
Private Declare Function DrawIcon Lib "user32" Alias "DrawIcon" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Path as String, strSave as string
'Create a buffer string
strSave = String(200, Chr$(0))
'Get the windows directory and append '\REGEdit.exe' to it
Path = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave))) + "\REGEdit.exe"
'No pictures
Picture1.Picture = LoadPicture()
'Set graphicmode to 'persistent
Picture1.AutoRedraw = True
'Extract the icon from REGEdit
return1& = ExtractIcon(Me.hWnd, Path, 2)
'Draw the icon on the form
return2& = DrawIcon(Picture1.hdc, 0, 0, return1&)
End Sub
3. Этот пример показывает, как найти папки Юзверей, там, по умолчанию, текущего или всех сразу.
Sample:- Код: Выделить всё
Private Const TOKEN_QUERY = (&H8)
Private Declare Function GetAllUsersProfileDirectory Lib "userenv.dll" Alias "GetAllUsersProfileDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
Private Declare Function GetDefaultUserProfileDirectory Lib "userenv.dll" Alias "GetDefaultUserProfileDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
Private Declare Function GetProfilesDirectory Lib "userenv.dll" Alias "GetProfilesDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
Private Declare Function GetUserProfileDirectory Lib "userenv.dll" Alias "GetUserProfileDirectoryA" (ByVal hToken As Long, ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@allapi.net
Dim sBuffer As String, Ret As Long, hToken As Long
'set the graphics mode of this form to 'persistent'
Me.AutoRedraw = True
'create a string buffer
sBuffer = String(255, 0)
'retrieve the all users profile directory
GetAllUsersProfileDirectory sBuffer, 255
'show the result
Me.Print StripTerminator(sBuffer)
'create a string buffer
sBuffer = String(255, 0)
'retrieve the user profile directory
GetDefaultUserProfileDirectory sBuffer, 255
'show the result
Me.Print StripTerminator(sBuffer)
'create a string buffer
sBuffer = String(255, 0)
'retrieve the profiles directory
GetProfilesDirectory sBuffer, 255
'show the result
Me.Print StripTerminator(sBuffer)
'create a string buffer
sBuffer = String(255, 0)
'open the token of the current process
OpenProcessToken GetCurrentProcess, TOKEN_QUERY, hToken
'retrieve this users profile directory
GetUserProfileDirectory hToken, sBuffer, 255
'show the result
Me.Print StripTerminator(sBuffer)
End Sub
'strips off the trailing Chr$(0)'s
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function