Results 1 to 15 of 15

Thread: Accessing path w/o knowing full path name

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Accessing path w/o knowing full path name

    I need access a file path, but a part of the path is different on each PC.

    Mozilla creates a random profile name for each PC it is installed on.

    I can get most of the path through environment variables. I need to access the files inside of the default profile, but can't since I'm not sure how to access it.

    Anyone have any ideas?

    Here's an example of the file path:

    'C:\Users\%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\xxxxxxxx.default'

    The only thing that stays the same with the profile name, is the '.default' part.

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,742

    Re: Accessing path w/o knowing full path name

    vb.net Code:
    1. Dim rootPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), _
    2.                                "Mozilla\Firefox\Profiles")
    3.  
    4. If IO.Directory.Exists(rootPath) Then
    5.     Dim defaultProfilePaths = IO.Directory.GetDirectories(rootPath, "*.default")
    6.  
    7.     'If there can be more than one.
    8.     For Each subfolderPath In defaultProfilePaths
    9.         MessageBox.Show(subfolderPath)
    10.     Next
    11.  
    12.     'If there can be zero or one.
    13.     MessageBox.Show(defaultProfilePaths.SingleOrDefault())
    14.  
    15.     'If there is always one.
    16.     MessageBox.Show(defaultProfilePaths.Single())
    17. End If

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,044

    Re: Accessing path w/o knowing full path name

    I hope this helps.

    EDIT: oopps, too late.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    29

    Re: Accessing path w/o knowing full path name

    Code:
    Dim rootPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), _
                                         "Mozilla\Firefox\")
            Dim objIniFile As New IniFile(rootPath & "profiles.ini")
            If IO.File.Exists(rootPath & "profiles.ini") = True Then
                Dim profile As String = objIniFile.GetString("Profile0", "Path", "")
                Dim Formatname As String = profile.Substring(Name.Length + 4)
                MsgBox(rootPath & "Profiles\" & Formatname)
            End If
    Code:
    Public Class IniFile
        Private Declare Ansi Function GetPrivateProfileString _
          Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
          (ByVal lpApplicationName As String, _
          ByVal lpKeyName As String, ByVal lpDefault As String, _
          ByVal lpReturnedString As System.Text.StringBuilder, _
          ByVal nSize As Integer, ByVal lpFileName As String) _
          As Integer
        Dim strFilename As String
    
        Public Sub New(ByVal Filename As String)
            strFilename = Filename
        End Sub
        Public Function GetString(ByVal Section As String, _
          ByVal Key As String, ByVal [Default] As String) As String
            ' Returns a string from your INI file
            Dim intCharCount As Integer
            Dim objResult As New System.Text.StringBuilder(512)
            intCharCount = GetPrivateProfileString(Section, Key, _
               [Default], objResult, objResult.Capacity, strFilename)
            If intCharCount > 0 Then GetString = _
               Left(objResult.ToString, intCharCount)
        End Function
    End Class
    I didn't code the class I found it online, I also used jmcilhinney rootPath. I'm to late as well.
    Last edited by chancity; Jul 16th, 2010 at 11:46 PM.

  5. #5

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: Accessing path w/o knowing full path name

    Thanks for the info!

    JMC, your example works perfectly.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Accessing path w/o knowing full path name

    Hello. I try to do this on the most recent versions of Mozilla Firefox, on Windows 10. However, it does not work, can you please help me ? I've tried your above code, thanks.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,742

    Re: Accessing path w/o knowing full path name

    Quote Originally Posted by Andrew2k View Post
    it does not work
    Then you did it wrong. If you don't show us what you did and tell us what actually happened then we'd need to be psychic to know what the problem is, or a very lucky guesser. The alternative is that you actually provide the information relevant to your problem.

  8. #8
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Accessing path w/o knowing full path name

    I use this in a module which should return Mozilla Firefox cookies, history, etc.
    Code:
    Private Function MozillaFireFoxPaths(ByVal pathType As String) As String
            Dim rootPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                   "Mozilla\Firefox\Profiles")
    
            Dim rootPath2 = profileAppDataLocal() & "\Mozilla\Firefox\Profiles"
    
            If Directory.Exists(rootPath) Then
                Dim defaultProfilePaths = Directory.GetDirectories(rootPath, "*.default")
    
                For Each subfolderPath In defaultProfilePaths
                    Select Case pathType
                        Case "cookies"
                            Return subfolderPath & "\cookies.sqlite"
                        Case "webappsstore"
                            Return subfolderPath & "\webappsstore.sqlite"
                        Case "downloads"
                            Return subfolderPath & "\downloads.sqlite"
                        Case "formhistory"
                            Return subfolderPath & "\formhistory.sqlite"
                        Case "cache"
                            Dim defaultProfilePaths2 = Directory.GetDirectories(rootPath2, "*.default")
    
                            For Each subfolderPath2 In defaultProfilePaths2
                                Return subfolderPath2 & "\cache"
                            Next
                        Case "sessionstore.js"
                            Return subfolderPath & "\sessionstore.js"
                        Case "sessionstore.bak"
                            Return subfolderPath & "\sessionstore.bak"
                        Case Else
                            Throw New ArgumentException("Exception Occured. Invalid argument for mozillaFireFoxPaths method.")
                    End Select
                Next
            End If
        End Function
    The above code works perfectly on Windows XP, however on Windows Vista, 7 and 10 it does not work, meaning that it does not return the required cookies, history to be deleted.

  9. #9
    Hyperactive Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    413

    Re: Accessing path w/o knowing full path name

    On W7, the paths are not the same...

    under AppData\Roaming\Mozilla\Firefox\Profiles\bj9kvlkk.default-1594028523097 (note that there is a number after default), I have the sqlite files (for example cookies.sqlite) directly in this folder and not in any subfolders and on AppData\Local\Mozilla\Firefox\Profiles\bj9kvlkk.default-1594028523097, I don't have any of these files and subfolders...
    Last edited by Delaney; Oct 26th, 2020 at 11:09 AM.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)

  10. #10
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Accessing path w/o knowing full path name

    I noticed now. How do I modify the code to fit the compatibility with Win7/Win10 ?

    I changed for it to get the files instead of getting nonexistent folders in Win7/Win10, this way :

    Code:
       If Directory.Exists(rootPath) Then
                Dim defaultProfilePaths = Directory.GetFiles(rootPath, "*.default")
    and still unable to get Cookies, History, etc.


    I even changed it to match the exact folder of the Firefox Profile:

    Code:
       If Directory.Exists(rootPath) Then
                Dim defaultProfilePaths = Directory.GetFiles(rootPath, "*.default-release")
    Still no remediation.
    Last edited by Andrew2k; Oct 26th, 2020 at 11:40 AM.

  11. #11
    Hyperactive Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    413

    Re: Accessing path w/o knowing full path name

    you can check for the windows version (see here ) and create the functions with different path and co. depending on the version
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)

  12. #12
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Accessing path w/o knowing full path name

    I only need compatibility with Windows 7, 8 and 10. There must be a single way to do it for all of those. How can I achieve that in VB.NET for Windows 7/8/10 ? Thanks in advance.

  13. #13
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Accessing path w/o knowing full path name

    Can someone please provide a reliable solution to this issue?
    Thank you.

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,742

    Re: Accessing path w/o knowing full path name

    Does Firefox store the root path in the Registry? If so, you should get the root path from the Registry first and then extend that using Path.Combine for each specific path.

  15. #15
    Junior Member
    Join Date
    Apr 2020
    Posts
    26

    Re: Accessing path w/o knowing full path name

    Unfortunately, Firefox does not seem to store the root path into the registry as far as I know.
    However, it stores cookies.sqlite and other history data in %APPDATA%\Roaming\Mozilla \Firefox\Profiles\ xxxx.default <- - - this 'xxx' is different on each PC. Inside this, there are the files which need to be deleted:cookies.sqlite, etc. I can't get it to work with the above code in Windows 7 and 10.

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