Results 1 to 9 of 9

Thread: appdata folder in vb6

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2010
    Posts
    377

    appdata folder in vb6

    need your assistance guys.

    what is the correct way to hardcode this path.

    In winxp, I need to create subfolder in the current users Documents and Settings folder and extract files there . . .

    or in vista or 7, I need to create subfolder in the current users Documents and Settings folder and extract files there . . .

    I dont want to hardcode C:\Documents and Settings\CustomFolder or C:\Users\CustomFolder because probably the working drive is D or E.

    Can I hardcode like %appdata%/customfolder?

    What is the correct code?

  2. #2
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: appdata folder in vb6

    Hi,

    Try these :

    MsgBox Environ$("AppData")
    MsgBox Environ$("AllUsersProfile")

    Regards
    Veena

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2010
    Posts
    377

    Re: appdata folder in vb6

    thank you very much. will this work with vista and 7 too?

  4. #4
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: appdata folder in vb6

    Hi,

    I dont know.. I have neither of them installed here...

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: appdata folder in vb6

    Take a look at this FAQ section http://www.vbforums.com/showthread.php?t=564256
    The code there is tested and works on Vista/7.

  6. #6
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: appdata folder in vb6

    The FAQ section answers a lot of common questions such as this.

    As far as I understand using Environment variables is not 100% reliable.

    If you want to know a little more about the API indirectly involved in the solution from the FAQ research...
    SHGetKnownFolderPath, SHGetFolderPath, KNOWNFOLDERID, CSIDL

    Edit: Baja has pipped me to the post
    Last edited by Milk; Dec 30th, 2010 at 07:56 AM. Reason: beaten to it
    W o t . S i g

  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: appdata folder in vb6

    Microsoft officially recommended using SHGetFolderPath API to retrieve the location of special folders in XP, meaning they have to keep supporting it for a long time going forward.
    vb Code:
    1. Public Enum FolderEnum
    2.     feCDBurnArea = 59 ' \Docs & Settings\User\Local Settings\Application Data\Microsoft\CD Burning
    3.     feCommonAppData = 35 ' \Docs & Settings\All Users\Application Data
    4.     feCommonAdminTools = 47 ' \Docs & Settings\All Users\Start Menu\Programs\Administrative Tools
    5.     feCommonDesktop = 25 ' \Docs & Settings\All Users\Desktop
    6.     feCommonDocs = 46 ' \Docs & Settings\All Users\Documents
    7.     feCommonPics = 54 ' \Docs & Settings\All Users\Documents\Pictures
    8.     feCommonMusic = 53 ' \Docs & Settings\All Users\Documents\Music
    9.     feCommonStartMenu = 22 ' \Docs & Settings\All Users\Start Menu
    10.     feCommonStartMenuPrograms = 23 ' \Docs & Settings\All Users\Start Menu\Programs
    11.     feCommonTemplates = 45 ' \Docs & Settings\All Users\Templates
    12.     feCommonVideos = 55 ' \Docs & Settings\All Users\Documents\My Videos
    13.     feLocalAppData = 28 ' \Docs & Settings\User\Local Settings\Application Data
    14.     feLocalCDBurning = 59 ' \Docs & Settings\User\Local Settings\Application Data\Microsoft\CD Burning
    15.     feLocalHistory = 34 ' \Docs & Settings\User\Local Settings\History
    16.     feLocalTempInternetFiles = 32 ' \Docs & Settings\User\Local Settings\Temporary Internet Files
    17.     feProgramFiles = 38 ' \Program Files
    18.     feProgramFilesCommon = 43 ' \Program Files\Common Files
    19.     'feRecycleBin = 10 ' ???
    20.     feUser = 40 ' \Docs & Settings\User
    21.     feUserAdminTools = 48 ' \Docs & Settings\User\Start Menu\Programs\Administrative Tools
    22.     feUserAppData = 26 ' \Docs & Settings\User\Application Data
    23.     feUserCache = 32 ' \Docs & Settings\User\Local Settings\Temporary Internet Files
    24.     feUserCookies = 33 ' \Docs & Settings\User\Cookies
    25.     feUserDesktop = 16 ' \Docs & Settings\User\Desktop
    26.     feUserDocs = 5 ' \Docs & Settings\User\My Documents
    27.     feUserFavorites = 6 ' \Docs & Settings\User\Favorites
    28.     feUserMusic = 13 ' \Docs & Settings\User\My Documents\My Music
    29.     feUserNetHood = 19 ' \Docs & Settings\User\NetHood
    30.     feUserPics = 39 ' \Docs & Settings\User\My Documents\My Pictures
    31.     feUserPrintHood = 27 ' \Docs & Settings\User\PrintHood
    32.     feUserRecent = 8 ' \Docs & Settings\User\Recent
    33.     feUserSendTo = 9 ' \Docs & Settings\User\SendTo
    34.     feUserStartMenu = 11 ' \Docs & Settings\User\Start Menu
    35.     feUserStartMenuPrograms = 2 ' \Docs & Settings\User\Start Menu\Programs
    36.     feUserStartup = 7 ' \Docs & Settings\User\Start Menu\Programs\Startup
    37.     feUserTemplates = 21 ' \Docs & Settings\User\Templates
    38.     feUserVideos = 14  ' \Docs & Settings\User\My Documents\My Videos
    39.     feWindows = 36 ' \Windows
    40.     feWindowFonts = 20 ' \Windows\Fonts
    41.     feWindowsResources = 56 ' \Windows\Resources
    42.     feWindowsSystem = 37 ' \Windows\System32
    43. End Enum
    44.  
    45. Private Declare Function SHGetFolderPath Lib "shfolder" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal pszPath As String) As Long
    46.  
    47. Public Function SpecialFolder(pfe As FolderEnum) As String
    48.     Const MAX_PATH = 260
    49.     Dim strPath As String
    50.     Dim strBuffer As String
    51.    
    52.     strBuffer = Space$(MAX_PATH)
    53.     If SHGetFolderPath(0, pfe, 0, 0, strBuffer) = 0 Then strPath = Left$(strBuffer, InStr(strBuffer, vbNullChar) - 1)
    54.     If Right$(strPath, 1) = "\" Then strPath = Left$(strPath, Len(strPath) - 1)
    55.     SpecialFolder = strPath
    56. End Function
    Sample usage:

    ?SpecialFolder(feUserAppData)
    C:\Documents and Settings\Ellis\Application Data

    ?SpecialFolder(feUserDocs)
    C:\Documents and Settings\Ellis\My Documents

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2010
    Posts
    377

    Re: appdata folder in vb6

    thanks for all the help here. I am very sorry if I am newbie and cant relate to all programming disciplines.

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: appdata folder in vb6

    Quote Originally Posted by iamresearcher View Post
    I am very sorry if I am newbie and cant relate to all programming disciplines.

    There's no need to apologise for being a newbie - we all were at one time, and like you, totally baffled by the mysteries of Operating Systems. As you gain more experience you'll find that, rather than bumping into constraints and treating them as irritations to be got round, you'll actually make use of them (and be thankful that the're there) !

    Happy New Year !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width