Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Finding the path to the pictures

Finding the path to the pictures

Scheduled Pinned Locked Moved Visual Basic
csharpjavascript
19 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JR212
    wrote on last edited by
    #1

    Hi, THIS IS NOT FOR .NET. I need this in vbs, js and vba I want to findout the path to the active user his pictures. I know how the find the documents, desktop of favorites throu specialfolders but pictures is'nt in it :( In google I didn't find anything usefull. Jan

    D Richard DeemingR 2 Replies Last reply
    0
    • J JR212

      Hi, THIS IS NOT FOR .NET. I need this in vbs, js and vba I want to findout the path to the active user his pictures. I know how the find the documents, desktop of favorites throu specialfolders but pictures is'nt in it :( In google I didn't find anything usefull. Jan

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There is no enumeration to get to Pictures from VBA and VBScript. Pictures was never added to those old things. Javascript in a browser has no access to the users filesystem so that's pretty much useless, unless you want to describe what you're doing with it. The work around is to just use the path of "%USERPROFILE%\Pictures".

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      L 1 Reply Last reply
      0
      • D Dave Kreskowiak

        There is no enumeration to get to Pictures from VBA and VBScript. Pictures was never added to those old things. Javascript in a browser has no access to the users filesystem so that's pretty much useless, unless you want to describe what you're doing with it. The work around is to just use the path of "%USERPROFILE%\Pictures".

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        ..that would be assuming a desktop with the English culture.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        J 1 Reply Last reply
        0
        • L Lost User

          ..that would be assuming a desktop with the English culture.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

          J Offline
          J Offline
          JR212
          wrote on last edited by
          #4

          indeed. This is not working for us:( this is a working pc and all data folders are on a nas server. thanks for the responses anyway. maybee I can find it in the registry? but where? Jan

          L 1 Reply Last reply
          0
          • J JR212

            Hi, THIS IS NOT FOR .NET. I need this in vbs, js and vba I want to findout the path to the active user his pictures. I know how the find the documents, desktop of favorites throu specialfolders but pictures is'nt in it :( In google I didn't find anything usefull. Jan

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            For VBA, you'll need to use either SHGetFolderPath[^] or the newer SHGetKnownFolderPath[^]. How To Use the SHGetFolderPath Function from Visual Basic[^]

            Option Explicit

            Private Const S_OK = &H0
            Private Const S_FALSE = &H1
            Private Const E_INVALIDARG = &H80070057

            Private Const MAX_PATH = 260
            Private Const SHGFP_TYPE_CURRENT = 0
            Private Const CSIDL_MYPICTURES = &H27

            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

            Private Function GetFolderPath(ByVal csidl As Long) As String
            Dim path As String
            Dim returnValue As Long

            path = String(MAX\_PATH, 0)
            returnValue = SHGetFolderPath(0, csidl, 0, SHGFP\_TYPE\_CURRENT, path)
            
            Select Case returnValue
                Case S\_OK
                    GetFolderPath = Left(path, InStr(1, path, Chr(0)) - 1)
                
                Case S\_FALSE
                    ' The CSIDL in nFolder is valid, but the folder does not exist.
                    ' Use CSIDL\_FLAG\_CREATE to have it created automatically
                    GetFolderPath = vbNullString
                
                Case E\_INVALIDARG
                    ' nFolder is invalid
                    Err.Raise 5, "csidl", "Invalid folder"
            End Select
            

            End Function

            Public Function GetPicturesFolderPath() As String
            GetPicturesFolderPath = GetFolderPath(CSIDL_MYPICTURES)
            End Function

            For script running locally, you could read the folder path from the registry (HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders). However, there is a warning in that key telling you not to do that! :) Since you can't call Windows functions directly from script, you'd need to create a COM object to call the Windows API, and invoke that object from your script. For script running in the browser, there is no way to

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            D J 2 Replies Last reply
            0
            • Richard DeemingR Richard Deeming

              For VBA, you'll need to use either SHGetFolderPath[^] or the newer SHGetKnownFolderPath[^]. How To Use the SHGetFolderPath Function from Visual Basic[^]

              Option Explicit

              Private Const S_OK = &H0
              Private Const S_FALSE = &H1
              Private Const E_INVALIDARG = &H80070057

              Private Const MAX_PATH = 260
              Private Const SHGFP_TYPE_CURRENT = 0
              Private Const CSIDL_MYPICTURES = &H27

              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

              Private Function GetFolderPath(ByVal csidl As Long) As String
              Dim path As String
              Dim returnValue As Long

              path = String(MAX\_PATH, 0)
              returnValue = SHGetFolderPath(0, csidl, 0, SHGFP\_TYPE\_CURRENT, path)
              
              Select Case returnValue
                  Case S\_OK
                      GetFolderPath = Left(path, InStr(1, path, Chr(0)) - 1)
                  
                  Case S\_FALSE
                      ' The CSIDL in nFolder is valid, but the folder does not exist.
                      ' Use CSIDL\_FLAG\_CREATE to have it created automatically
                      GetFolderPath = vbNullString
                  
                  Case E\_INVALIDARG
                      ' nFolder is invalid
                      Err.Raise 5, "csidl", "Invalid folder"
              End Select
              

              End Function

              Public Function GetPicturesFolderPath() As String
              GetPicturesFolderPath = GetFolderPath(CSIDL_MYPICTURES)
              End Function

              For script running locally, you could read the folder path from the registry (HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders). However, there is a warning in that key telling you not to do that! :) Since you can't call Windows functions directly from script, you'd need to create a COM object to call the Windows API, and invoke that object from your script. For script running in the browser, there is no way to

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Richard Deeming wrote:

              However, there is a warning in that key telling you not to do that!

              I thought you mistyped this until I went and looked at the key. No, you didn't. It's in there! :-D The path to Pictures is listed as "My Pictures", but like you said before, is this name localized? I have no idea.

              A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              Richard DeemingR 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Richard Deeming wrote:

                However, there is a warning in that key telling you not to do that!

                I thought you mistyped this until I went and looked at the key. No, you didn't. It's in there! :-D The path to Pictures is listed as "My Pictures", but like you said before, is this name localized? I have no idea.

                A guide to posting questions on CodeProject

                Click this: Asking questions is a skill. Seriously, do it.
                Dave Kreskowiak

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                I don't think the names would be localized, but I don't have a non-English version of Windows to check. I've just added a link to a blog post from Raymond Chen, who explains that the "Shell Folders" key exists solely to permit four programs written in 1994 to continue running on the RTM version of Windows 95. :wtf:


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                L D 2 Replies Last reply
                0
                • Richard DeemingR Richard Deeming

                  I don't think the names would be localized, but I don't have a non-English version of Windows to check. I've just added a link to a blog post from Raymond Chen, who explains that the "Shell Folders" key exists solely to permit four programs written in 1994 to continue running on the RTM version of Windows 95. :wtf:


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  The names are localized. I got a folder "My Pictures", one called "Pictures" and one "Mijn Afbeeldingen". To make things worse, this does not say anything about the actual location, as my "Mijn Afbeeldingen" points to a completely different harddrive. More on Wikipedia[^].

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  Richard DeemingR 1 Reply Last reply
                  0
                  • J JR212

                    indeed. This is not working for us:( this is a working pc and all data folders are on a nas server. thanks for the responses anyway. maybee I can find it in the registry? but where? Jan

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Alternatively, you could ask the user for the location.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                    1 Reply Last reply
                    0
                    • L Lost User

                      The names are localized. I got a folder "My Pictures", one called "Pictures" and one "Mijn Afbeeldingen". To make things worse, this does not say anything about the actual location, as my "Mijn Afbeeldingen" points to a completely different harddrive. More on Wikipedia[^].

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #10

                      I'd expect the names of the folders to be localized. But what about the names of the values in the "User Shell Folders" registry key?


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      L 1 Reply Last reply
                      0
                      • Richard DeemingR Richard Deeming

                        I'd expect the names of the folders to be localized. But what about the names of the values in the "User Shell Folders" registry key?


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Richard Deeming wrote:

                        I'd expect the names of the folders to be localized

                        Yup.

                        Richard Deeming wrote:

                        But what about the names of the values in the "User Shell Folders" registry key?

                        Yes, my apologies for not thinking. English, both on a Dutch and a German machine. Called "CommonPictures" on this machine, pointing to the correct physical path. Keys are usually not translated, because that would defeat the purpose of having one. ..so, remotely reading the registry as an admin, just to find a path? Still sounds like a bad idea :)

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                        D 1 Reply Last reply
                        0
                        • Richard DeemingR Richard Deeming

                          I don't think the names would be localized, but I don't have a non-English version of Windows to check. I've just added a link to a blog post from Raymond Chen, who explains that the "Shell Folders" key exists solely to permit four programs written in 1994 to continue running on the RTM version of Windows 95. :wtf:


                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #12

                          Ow! I just fell out of my chair laughing. :laugh: That's one hell of a "fix". :wtf:

                          A guide to posting questions on CodeProject

                          Click this: Asking questions is a skill. Seriously, do it.
                          Dave Kreskowiak

                          L 1 Reply Last reply
                          0
                          • L Lost User

                            Richard Deeming wrote:

                            I'd expect the names of the folders to be localized

                            Yup.

                            Richard Deeming wrote:

                            But what about the names of the values in the "User Shell Folders" registry key?

                            Yes, my apologies for not thinking. English, both on a Dutch and a German machine. Called "CommonPictures" on this machine, pointing to the correct physical path. Keys are usually not translated, because that would defeat the purpose of having one. ..so, remotely reading the registry as an admin, just to find a path? Still sounds like a bad idea :)

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            Eddy Vluggen wrote:

                            nglish, both on a Dutch and a German machine. Called "CommonPictures" on this machine, pointing to the correct physical path. Keys are usually not translated, because that would defeat the purpose of having one.

                            Considering the "fix" that this key was created for, would it really surprise anyone if someone at MS did something that stupid?

                            A guide to posting questions on CodeProject

                            Click this: Asking questions is a skill. Seriously, do it.
                            Dave Kreskowiak

                            1 Reply Last reply
                            0
                            • D Dave Kreskowiak

                              Ow! I just fell out of my chair laughing. :laugh: That's one hell of a "fix". :wtf:

                              A guide to posting questions on CodeProject

                              Click this: Asking questions is a skill. Seriously, do it.
                              Dave Kreskowiak

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              His blog is filled with those kind of examples. Well worth the read if you have some time to kill :)

                              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                              D 1 Reply Last reply
                              0
                              • L Lost User

                                His blog is filled with those kind of examples. Well worth the read if you have some time to kill :)

                                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                                D Offline
                                D Offline
                                Dave Kreskowiak
                                wrote on last edited by
                                #15

                                "Time"? What is this "time" you speak of? I'm in the middle of a 6 week stint of being a single parent while the wife travels for work. 24 hours in a day isn't enough. I have to give credit to those who do this full-time. It ain't easy.

                                A guide to posting questions on CodeProject

                                Click this: Asking questions is a skill. Seriously, do it.
                                Dave Kreskowiak

                                1 Reply Last reply
                                0
                                • Richard DeemingR Richard Deeming

                                  For VBA, you'll need to use either SHGetFolderPath[^] or the newer SHGetKnownFolderPath[^]. How To Use the SHGetFolderPath Function from Visual Basic[^]

                                  Option Explicit

                                  Private Const S_OK = &H0
                                  Private Const S_FALSE = &H1
                                  Private Const E_INVALIDARG = &H80070057

                                  Private Const MAX_PATH = 260
                                  Private Const SHGFP_TYPE_CURRENT = 0
                                  Private Const CSIDL_MYPICTURES = &H27

                                  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

                                  Private Function GetFolderPath(ByVal csidl As Long) As String
                                  Dim path As String
                                  Dim returnValue As Long

                                  path = String(MAX\_PATH, 0)
                                  returnValue = SHGetFolderPath(0, csidl, 0, SHGFP\_TYPE\_CURRENT, path)
                                  
                                  Select Case returnValue
                                      Case S\_OK
                                          GetFolderPath = Left(path, InStr(1, path, Chr(0)) - 1)
                                      
                                      Case S\_FALSE
                                          ' The CSIDL in nFolder is valid, but the folder does not exist.
                                          ' Use CSIDL\_FLAG\_CREATE to have it created automatically
                                          GetFolderPath = vbNullString
                                      
                                      Case E\_INVALIDARG
                                          ' nFolder is invalid
                                          Err.Raise 5, "csidl", "Invalid folder"
                                  End Select
                                  

                                  End Function

                                  Public Function GetPicturesFolderPath() As String
                                  GetPicturesFolderPath = GetFolderPath(CSIDL_MYPICTURES)
                                  End Function

                                  For script running locally, you could read the folder path from the registry (HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders). However, there is a warning in that key telling you not to do that! :) Since you can't call Windows functions directly from script, you'd need to create a COM object to call the Windows API, and invoke that object from your script. For script running in the browser, there is no way to

                                  J Offline
                                  J Offline
                                  JR212
                                  wrote on last edited by
                                  #16

                                  i'll give this a try thanks to all btw I already found that reg key:) Jan

                                  J 1 Reply Last reply
                                  0
                                  • J JR212

                                    i'll give this a try thanks to all btw I already found that reg key:) Jan

                                    J Offline
                                    J Offline
                                    JR212
                                    wrote on last edited by
                                    #17

                                    I've got this mail

                                    Your message 'Re: Finding the path to the pictures' has been marked as potentially being spam and is currently in the moderation queue pending approval.

                                    Why????

                                    D 1 Reply Last reply
                                    0
                                    • J JR212

                                      I've got this mail

                                      Your message 'Re: Finding the path to the pictures' has been marked as potentially being spam and is currently in the moderation queue pending approval.

                                      Why????

                                      D Offline
                                      D Offline
                                      Dave Kreskowiak
                                      wrote on last edited by
                                      #18

                                      Because the site spam filters don't trust you nor your message. Yes, it does come up with a bunch of false positives. No, there's nothing you can do about it.

                                      A guide to posting questions on CodeProject

                                      Click this: Asking questions is a skill. Seriously, do it.
                                      Dave Kreskowiak

                                      J 1 Reply Last reply
                                      0
                                      • D Dave Kreskowiak

                                        Because the site spam filters don't trust you nor your message. Yes, it does come up with a bunch of false positives. No, there's nothing you can do about it.

                                        A guide to posting questions on CodeProject

                                        Click this: Asking questions is a skill. Seriously, do it.
                                        Dave Kreskowiak

                                        J Offline
                                        J Offline
                                        JR212
                                        wrote on last edited by
                                        #19

                                        thx Dave

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups