VS 2010 [RESOLVED] ProgramData Folder (SpecialDirectories)-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] ProgramData Folder (SpecialDirectories)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    15

    [RESOLVED] ProgramData Folder (SpecialDirectories)

    How can I write ProgramData path?

    Example:
    Code:
    TextBox1.Text = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
    Whit this code I'm getting "C:\ProgramData\Microsoft\ProgramData\1.0.0.0" (Win7), but I need something like this:
    Vista/7 = C:\ProgramData
    XP = C:\Documents and Settings\All Users\Application Data
    Last edited by rossi_4656; Oct 24th, 2011 at 12:21 PM.

  2. #2
    Lively Member
    Join Date
    Apr 2006
    Posts
    68

    Re: ProgramData Folder (SpecialDirectories)

    G'd Afternoon,
    May be i don't understand your question. If you request the AllUsersApplicationData folder path, that's what you get. If you just want the paths above mentioned you may hard code them and check for the OS Name (WMI Library) or use the Microsoft.Win32 library to get the OS Version and set the paths accordingly. Something like this:
    Code:
    Imports Microsoft.Win32
    Private sub SetPath() as string
            Dim osInfo As OperatingSystem
            Dim oVer As Version
           
    
            'OS Version
            'Version 5: XP and Sever 2003 family
            'Version 6: Vista/Win7/Server 2008 Family
    
            osInfo = Environment.OSVersion
            oVer = osInfo.Version
    
            Select Case CShort(oVer.Major)
                      Case 5
                              Return "C:\Documents and Settings\All Users\Application Data"
                      Case 6
                             Return "C:\ProgramData"
                      Case Else
                             Return string.empty
                End Select
    End Function

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,293

    Re: ProgramData Folder (SpecialDirectories)

    Quote Originally Posted by rossi_4656 View Post
    How can I write ProgramData path?

    Example:
    Code:
    TextBox1.Text = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
    Whit this code I'm getting "C:\ProgramData\Microsoft\ProgramData\1.0.0.0" (Win7), but I need something like this:
    Vista/7 = C:\ProgramData
    XP = C:\Documents and Settings\All Users\Application Data
    The path is different for each of the OS you have listed which is why a different folder is returned.

    http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

    Make sure to read the Remarks section.

  4. #4
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: ProgramData Folder (SpecialDirectories)

    vb Code:
    1. Label1.Text = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
    result is [w7 64] = C:\ProgramData\Microsoft\WindowsApplication1\1.0.0.0


    using Environment...
    vb Code:
    1. Label2.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
    result is [w7 64] = C:\ProgramData

    vb Code:
    1. Label2.Text = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
    result is [w7 64] = C:\Users\venice\AppData\Local


    vb Code:
    1. Label2.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    result is [w7 64] = C:\Users\venice\AppData\Roaming

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    15

    Re: ProgramData Folder (SpecialDirectories)

    Quote Originally Posted by medsont View Post
    vb Code:
    1. Label1.Text = My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
    result is [w7 64] = C:\ProgramData\Microsoft\WindowsApplication1\1.0.0.0


    using Environment...
    vb Code:
    1. Label2.Text = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
    result is [w7 64] = C:\ProgramData

    vb Code:
    1. Label2.Text = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
    result is [w7 64] = C:\Users\venice\AppData\Local


    vb Code:
    1. Label2.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    result is [w7 64] = C:\Users\venice\AppData\Roaming
    Thank you very much!

  6. #6
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: [RESOLVED] ProgramData Folder (SpecialDirectories)

    u r so welcome.........

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.