-
Jul 16th, 2010, 10:45 PM
#1
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
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 16th, 2010, 11:00 PM
#2
Re: Accessing path w/o knowing full path name
vb.net Code:
Dim rootPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), _ "Mozilla\Firefox\Profiles") If IO.Directory.Exists(rootPath) Then Dim defaultProfilePaths = IO.Directory.GetDirectories(rootPath, "*.default") 'If there can be more than one. For Each subfolderPath In defaultProfilePaths MessageBox.Show(subfolderPath) Next 'If there can be zero or one. MessageBox.Show(defaultProfilePaths.SingleOrDefault()) 'If there is always one. MessageBox.Show(defaultProfilePaths.Single()) End If
-
Jul 16th, 2010, 11:06 PM
#3
Re: Accessing path w/o knowing full path name
I hope this helps.
EDIT: oopps, too late.
-
Jul 16th, 2010, 11:12 PM
#4
Junior Member
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.
-
Jul 19th, 2010, 10:50 PM
#5
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
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Oct 26th, 2020, 06:46 AM
#6
Banned
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.
-
Oct 26th, 2020, 08:24 AM
#7
Re: Accessing path w/o knowing full path name
Originally Posted by Andrew2k
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.
-
Oct 26th, 2020, 09:16 AM
#8
Banned
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.
-
Oct 26th, 2020, 11:04 AM
#9
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)
“They did not know it was impossible so they did it” (Mark Twain)
-
Oct 26th, 2020, 11:34 AM
#10
Banned
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.
-
Oct 26th, 2020, 12:37 PM
#11
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)
“They did not know it was impossible so they did it” (Mark Twain)
-
Oct 26th, 2020, 12:45 PM
#12
Banned
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.
-
Oct 28th, 2020, 03:28 PM
#13
Banned
Re: Accessing path w/o knowing full path name
Can someone please provide a reliable solution to this issue?
Thank you.
-
Oct 28th, 2020, 07:31 PM
#14
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.
-
Oct 28th, 2020, 08:17 PM
#15
Banned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|