0

I'm trying to create a batch file who will search for a specified file and will replace a string in it by something else

The problem is that the path is different for each user.

The file is prefs.js, and it's located in C:\%username%\AppData\Roaming\Thunderbird\Profiles\xxxxxxx.default\prefs.js

Is that possible ?

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • You want each user to change the string? Or to do it from admin account? Check this also - http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir – npocmaka Mar 17 '17 at 18:05
  • 1
    Is _"the path different for each user"_ or is the file _"located in `C:\%username%\AppData\Roaming\Thunderbird\Profiles\xxxxxxx.default\prefs.js`"_??? (I think your are answering your own question) – Aacini Mar 17 '17 at 18:40
  • Do you need to identify the `xxxxxxx` string (which is different for each user in `xxxxxxx.default` folder name)? Yes, that's possible although I daresay that instead of `C:\%username%\AppData\Roaming` should be `%userprofile%\AppData\Roaming` or even `%appdata%` should suffice. – JosefZ Mar 17 '17 at 19:39
  • 1
    So you want to __manipulate/hack__ the preferences file of Thunderbird. This is usually done only by bad guys which we call `hacker` or in your case `script kiddie` and whom I don't want to help. But I answer nevertheless your question: __Yes, it is possible.__ – Mofi Mar 18 '17 at 14:36
  • I don't want to hack the prefs.js, I want to use .batch file in a GPO to replace a wrong string in prefs.js, I don't want to do it manually for 500+ users. The problem is that the prefs.js is not located in the same directory for each user. This path section is different for each user \xxxxxxx.d‌​efault\ So i need a .batch who is able to find the prefs.js and can find and replace a string in the prefs.js. I'm french so sorry if my question is not 100% clear – Hugo Poirier Mar 20 '17 at 19:00
  • Run in a command prompt window `dir /?` and `for /?` and read the output help pages. Then it should be not too difficult to write the code which searches in directory `%APPDATA%\Thunderbird\Profiles` and its subdirectories for all `prefs.js` and update a string using one of the methods posted for example at [How can you find and replace text in a file using the Windows command-line environment?](http://stackoverflow.com/questions/60034/) – Mofi Mar 21 '17 at 17:53

2 Answers2

0

Whilst I'm aware that this isn't a complete answer, it may get you so far or possibly even make you rethink your methodology.

I'm not sure if you are aware that each end user can have multiple profiles and hence profile folders. In addition they can have those folders named however they like not just the *.default names, (which may not exist at all), and they can be in any location too.

There is however a method to determine those names and paths, because there is a file named profiles.ini located in the %AppData%\Thunderbird directory which defines that information.

What follows is an untested example script which should set variables to the available prefs.js files for a single user.

@Echo Off
Set "PF=%AppData%\Thunderbird\"
If Not Exist "%PF%" GoTo :EndIt
Set "i=0"
For /F "Tokens=1* Delims==" %%A In (
    'FindStr/R "^Path=.*" "%PF%Profiles.ini"') Do (Set "TP=%%B"
    Call :Sub "%%TP:/=\%%")
Set PJ[
:EndIt
Echo( Press any key to exit...
Timeout -1 1>Nul
Exit/B
    :Sub
    Set/A i+=1
    If Exist "%PF%%~1\" (Set "PJ[%i%]=%PF%%~1\prefs.js"
        ) Else Set "PJ[%i%]=%~1\prefs.js"
Compo
  • 36,585
  • 5
  • 27
  • 39
0

Why not just use *.default in your path ?

Did you ever see a Thunderbird with two .default directory ? If yes, is your modification can be a problems in another profile ?

Sometimes simple is better than complicated :)

D B
  • 1