当前位置:编程学习 > VB >>

vb获取启动文件夹路径

答案:Private Const CSIDL_Users_STARTMENU_a = &H7 '当前用户\开始-程序-启动
' 声明API函数

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long

Private Function GetSpecialPath(CSIDL As Long) As String

    Dim s As Long

    Dim path As String

    Dim pidl As Long

    '根据指定的文件夹获得pidl

    s = SHGetSpecialFolderLocation(Me.hWnd, CSIDL, pidl)

    If s = NOERROR Then ' 根据r的返回值判断是否有错误发生,如果没有错误就获取文件夹路径

        path = Space$(512)

        s = SHGetPathFromIDList(ByVal pidl, ByVal path)

        GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1)

        Exit Function

    End If

    GetSpecialPath = ""

End Function


Private Sub Form_Load()
msgbox GetSpecialPath(CSIDL_Users_STARTMENU_a) & "\"
End Sub

 

 

 

 

其它参数

Private Const NOERROR = 0

Private Const CSIDL_Users_FAVORITES = &H6 '当前用户\收藏夹

Private Const CSIDL_Users_DESKTOPDIRECTORY = &H10 '当前用户\桌面

Private Const CSIDL_Users_STARTMENU = &HB '当前用户\开始菜单

Private Const CSIDL_Users_STARTMENU_cx = &H2 '当前用户\开始-程序

Private Const CSIDL_Users_MyDocuments = &H5 '当前用户\我的文档

Private Const CSIDL_Users_STARTMENU_a = &H7 '当前用户\开始-程序-启动

Private Const CSIDL_Users_Recent = &H8 '当前用户\'Recent

Private Const CSIDL_Users_SendTo = &H9 '当前用户\SendTo

Private Const CSIDL_Users_MyMusic = &HD '当前用户\My Documents\My Music\

Private Const CSIDL_Users_NetHood = &H13 '当前用户\NetHood

Private Const CSIDL_Users_Templates = &H15 '当前用户\Templates

Private Const CSIDL_Users_AppData = &H1A '当前用户\Application Data\

Private Const CSIDL_Users_PrintHood = &H1B '当前用户\PrintHood\

Private Const CSIDL_Users_Local_AppData = &H1C '当前用户\Local Settings\Application Data\

Private Const CSIDL_Users_Temp = &H20 '当前用户\Local Settings\Temporary Internet Files\

Private Const CSIDL_Users_Cookies = &H21 '当前用户\Cookies\

Private Const CSIDL_Users_History = &H22 '当前用户\Local Settings\History\

Private Const CSIDL_Users_Pictures = &H27 '当前用户\My Documents\My Pictures\

Private Const CSIDL_Users = &H28 '当前用户\

Private Const CSIDL_Users_gl = &H30 '当前用户\「开始」菜单\程序\管理工具\

Private Const CSIDL_Users_CDBurning = &H3B '当前用户\Local Settings\Application Data\Microsoft\CD Burning\

Private Const CSIDL_AllUsers_STARTMENU = &H16 'All Users\「开始」菜单\

Private Const CSIDL_AllUsers_STARTMENU_cx = &H17 'All Users\「开始」菜单\程序\

Private Const CSIDL_AllUsers_STARTMENU_j = &H18 'All Users\「开始」菜单\程序\启动\

Private Const CSIDL_AllUsers_DESKTOPDIRECTORY = &H19 'All Users\桌面

Private Const CSIDL_AllUsers_FAVORITES = &H1F 'All Users\Favorites\(收藏夹)

Private Const CSIDL_AllUsers_Templates = &H2D 'All Users\Templates\

Private Const CSIDL_AllUsers_Documents = &H2E 'All Users\Documents\

Private Const CSIDL_AllUsers_gl = &H2F 'All Users\「开始」菜单\程序\管理工具\

Private Const CSIDL_AllUsers_Music = &H35 'All Users\Documents\My Music\

Private Const CSIDL_AllUsers_Pictures = &H36 'All Users\Documents\My Pictures\

Private Const CSIDL_AllUsers_Videos = &H37 'All Users\Documents\My Videos\

Private Const CSIDL_AllUsers_AppData = &H23 'All Users\Application Data\

Private Const CSIDL_WinDows = &H24 '系统安装路径 C:\WINDOWS\

Private Const CSIDL_WinSystem = &H25 '系统文件夹 C:\WINDOWS\system32\

Private Const CSIDL_ProgramFiles = &H26 '应用程序安装文件夹 C:\Program Files\

Private Const CSIDL__ProgramFiles_CommonFiles = &H2B 'C:\Program Files\Common Files\

Private Const CSIDL_WIN_Resources = &H38 'C:\WINDOWS\Resources\

Private Const CSIDL_font = &H14 '字体文件夹C:\WINDOWS\Fonts\

 

上一个:VB怎样让密码显示圆点
下一个:VB 二维数组定义的问题!

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,