I have a scheduled task in Windows Server 2003 R2 that is supposed get some files from a network location (mapped drive) and copy them to a local folder in preparation for an FTP sync to a mobile device later that day.
The task runs no problem when I click it and run it. Task scheduler says it is running updates the time it has run and the files appear in the correct location. Yet...
When the task is supposed to run over night (and I am not already logged in) the task runs (task scheduler indicates that the task ran at the specified time) but the file copy does not occur. I suspect this has to do with the task logging the account in, then running the file copy before the Network Drive has been connected and is ready.
Here is my code from the batch file:
#echo off
FORFILES /p "K:\Oncology\BSWRICS-MDM" /s /m *.* /c "cmd /c Del #path" /d -30
set "cleanup=K:\Oncology\BSWRICS-MDM"
for /f "usebackq tokens=*" %%a in (`dir /b/s/ad "%cleanup%" ^| sort /r`) do (rmdir "%%~a" 2>nul && echo:Removed: "%%a")
xcopy K:\Oncology\BSWRICS-MDM\*.* C:\wamp\www\Portal\files\BSWRICS-MDM /Y /S
FORFILES /p "C:\wamp\www\Portal\files\BSWRICS-MDM" /s /m *.* /c "cmd /c Del #path" /d -30
The first few lines delete files older than 30 days from the local folder, then the xcopy occurs. As I said, this script works perfectly when I log in first.
Is there some code I can insert at the start to have the script check if the network drive is ready and only if TRUE, proceed to the next instruction?
Some answers to expected questions:
- The network drive letter never changes.
- The account that logs in with the scheduled task is the same one I can successfully run the task from.
- The task actually runs (logged in task scheduler) but there is no evidence of the file copy having been performed.
Thanks in advance.
You could delete the mapped drive and try to map it again, and then wait until the errorlevel shows it is connected before proceeding.
#echo off
:LOOP
net use Y: /delete
net use Y: \\server\share
if errorlevel 1 (
goto :ERROR
) else (
goto :OK
)
:ERROR
echo ERROR!
rem Try again!
timeout /t 5
goto :LOOP
:OK
echo OK!
rem Carry on!
pause >nul
Related
I'm writing a batch file for Windows 7.
I currently have a code that deletes old backups from our masters folders within our site management folders. This is the code:
for /d %%A in ("Y:\*.*") do del /s /q /f "%%A\masters\*.bak"
However I need to code it to only delete things that are older than 3 years, which would be this code:
forfiles /P "Y:\" /S /D -1096 /M *.bak /C "cmd /C del #path"
However I need what is in the top code so that I can delete all *.bak files from the masters folders that exist within our 173 site management folders. I'm ripping my hair out figuring this out. I can't have it deleting *.bak files from our other folders.
I've tried combining the code, but below command line in batch file does not work as expected:
forfiles /S /D -1096 /M *.bak /C "cmd /C for /d %%A in ("Y:\*.*") do del /s /q /f "%%A\masters\*.bak"
How to delete all *.bak files older than 3 years anywhere in directory tree if second directory in file path is masters and keep all other *.bak files being newer or in a directory where second directory in file path is not masters?
Create first a batch file C:\Temp\DeleteBackup.bat with the following commands:
#echo off
set "BackupFileName=%~1"
if not "%BackupFileName:\masters\=%" == "%BackupFileName%" ECHO del "%BackupFileName%"
This batch code checks if the file name with full path and file extension contains anywhere \masters\ by removing this string case-insensitive from left argument of string comparison.
If the remaining string is not equal the unmodified file name string because of containing \masters\ in path, the IF condition is true and the backup file would be deleted if there would not be command ECHO which results in just displaying the DEL command line.
For example the complete list of backup files is:
Y:\masters\Level2\Level3\Level4\Level5\Test1.bak
Y:\Folder2\masters\Level3\Test2.bak
Y:\Folder3\Level2\masters\Level4\Test3.bak
Y:\Folder4\Level2\Level3\Level4\Level5\Test4.bak
Y:\Folder5\Level2\Test5.bak
Y:\Folder6\Level2\Level3\Level4\Level5\Level6\Test6.bak
Y:\Folder7\masters\Test7.bak
The files deleted would be:
Y:\masters\Level2\Level3\Level4\Level5\Test1.bak
Y:\Folder2\masters\Level3\Test2.bak
Y:\Folder3\Level2\masters\Level4\Test3.bak
Y:\Folder7\masters\Test7.bak
And the files remaining would be:
Y:\Folder4\Level2\Level3\Level4\Level5\Test4.bak
Y:\Folder5\Level2\Test5.bak
Y:\Folder6\Level2\Level3\Level4\Level5\Level6\Test6.bak
Then use in your batch file:
forfiles /P "Y:\" /S /D -1096 /M *.bak /C "C:\Temp\DeleteBackup.bat #PATH"
It is of course possible to modify DeleteBackup.bat to check if directory in second directory hierarchy level is masters.
#echo off
for /F "tokens=3 delims=\" %%I in ("%~1") do if /I "%%I" == "masters" ECHO del "%~1"
This code would delete from the complete list above the files:
Y:\Folder2\masters\Level3\Test2.bak
Y:\Folder7\masters\Test7.bak
And the files remaining would be:
Y:\masters\Level2\Level3\Level4\Level5\Test1.bak
Y:\Folder3\Level2\masters\Level4\Test3.bak
Y:\Folder4\Level2\Level3\Level4\Level5\Test4.bak
Y:\Folder5\Level2\Test5.bak
Y:\Folder6\Level2\Level3\Level4\Level5\Level6\Test6.bak
Robert Chizmadia Jr. asked in an already deleted comment:
Is it possible to use GOTO instead of calling another batch file on FORFILES command line?
The answer on this additional question:
FORFILES is not an internal command of cmd.exe like FOR. It is a console application stored in directory %SystemRoot%\System32 if used version of Windows has it pre-installed at all.
The command to execute as specified after FORFILES option /C must be an executable or script. That is the reason why cmd /C is always used when an internal command of Windows command interpreter cmd.exe like DEL should be executed by FORFILES whereby the really complete command would be %SystemRoot%\System32\cmd.exe /C.
So it is not possible to use a command like GOTO in FORFILES command as there is no executable or script with name GOTO.
Also GOTO in a FOR loop exits the loop and therefore interpreting of command lines of batch files continues on another position in batch file.
However, it is possible to use the same batch file for the file path evaluation and backup file deletion as used to run FORFILES command.
Example 1 with batch file not expecting any parameter for default operation:
#echo off
if not "%~1" == "" (
for /F "tokens=3 delims=\" %%I in ("%~1") do if /I "%%I" == "masters" ECHO del "%~1"
goto :EOF
)
%SystemRoot%\System32\forfiles.exe /P "Y:\" /S /D -1096 /M *.bak /C "%~f0 #PATH"
If this batch file is executed with an argument, it runs the FOR loop written to check if second directory in file path is masters and delete this file in this case after removing ECHO. Otherwise on starting the batch file without any parameter the batch file runs the FORFILES executable.
Example 2 with batch file expecting 1 or more parameters for default operation:
#echo off
if "%~1" == "#Delete:Backup#" (
for /F "tokens=3 delims=\" %%I in ("%~2") do if /I "%%I" == "masters" ECHO del "%~2"
goto :EOF
)
rem Other commands processing the parameters.
%SystemRoot%\System32\forfiles.exe /P "Y:\" /S /D -1096 /M *.bak /C "%~f0 #Delete:Backup# #PATH"
rem More commands executed after the deletion of the backup files.
This is nearly the same as example 1 with the difference that if first parameter used on running the batch file is case-sensitive the string #Delete:Backup#, the batch file expects as second parameter the name of a backup file with full path being deleted if second directory in file path is masters.
Like in all batch code examples the command ECHO must be removed before del command also in this code example to really execute the deletion of the backup files.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
forfiles /?
goto /?
if /?
set /?
I have written batch file to delete a .zip extension file after 70 days we below
forfiles /p "%SourceFolderLocation%" /s /m *.zip /c "cmd /c Del #path" /d -%NumberOfDaysForFolderToExists%
I am using this batch file in Jenkis Job. whenever the delete batch file is not getting the specified file which is older than specified date then jenkins job is failing.
Do we have any way to stop the jenkins job fail if the file is not found to delete also?
Thanks in Advance....
ForFiles Return values:
If ForFiles finds one or more matches if will return Errorlevel =0
If ForFiles finds no matches if will return Errorlevel =1 and
will print "ERROR: No files found with the specified search
criteria."
Suppress forfiles command error message as 2>NUL forfiles /p …, or
Force Errorlevel to 0, e.g. by (call ) command, and/or
Force your script to return Errorlevel of 0 by exit /B 0 command.
The whole script could be as follows (if forfiles is the only cause of Jenkins job fail):
rem … (previous commands here)
2>NUL forfiles /p "%SourceFolderLocation%" /s /m *.zip /c "cmd /c Del #path" /d -%NumberOfDaysForFolderToExists%
(call )
rem … (next commands here)
exit /B 0
For the (call ) trick explanation, see Dave Benham's reply to setting ERRORLEVEL to 0 question:
If you want to force the errorlevel to 0, then you can use this
totally non-intuitive, but very effective syntax: (call ). The space
after call is critical. If you want to set the errorlevel to 1, you
can use (call). It is critical that there not be any space after
call.
So I'm trying to copy a backup of the data from my app. I wrote the batch script below to do this, but the script takes forever to run.
I start the batch script at 1am, and it is still running at 8:30am. This seems weird to me because when I copy the backup of my app manually in Windows File Explorer, it copies in 7-15 minutes depending on network traffic.
I REM the %backupcmd% "C:\Program Files\App\App Server\Data\Backups" "%drive%\" line. That was the original line of batch script I used to backup the data, and it worked efficiently up till a month ago.
So I tried the xcopy command with /d, so it would only copy source files that have been changed on or after that date (the current date), and the backups I'm copying are made at 12:01am every night and the copy backup script starts at 1am.
Any advice as to how to speed up my xcopy would be appreciated. If you think I should use powershell for this task too, I'm open to that option as well.
#echo off
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set yyyy=%ldt:~0,4%
set mm=%ldt:~4,2%
set dd=%ldt:~6,2%
:: variables
set drive=Z:\RootSoft\App\Data Backups
set backupcmd=xcopy /s /c /d /e /h /i /r /y /f /z
echo ### Backing up Backup...
REM %backupcmd% "C:\Program Files\App\App Server\Data\Backups" "%drive%\"
xcopy "C:\Program Files\App\App Server\Data\Backups" "Z:\RootSoft\App\Data Backups" /D:%mm%-%dd%-%yyyy% /s /c /e /h /i /r /y /f /z
:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."
echo Backup Complete!
echo %errorlevel%
pause
You could try with ROBOCOPY and /MT switch which could accelerate the copy.
Also you can make some test by measuring the during process with TimeThis that can be found here (no need to be installed, just extract the exe with 7z in the current batch file folder)
netsh interface tcp show global
netsh int tcp set heuristics disabled
netsh int tcp set global autotuninglevel=disabled
netsh int ip set global taskoffload=disabled
I have a bunch of old machines running Windows 2000 Pro and IE 5.0 which I want to upgrade to IE 6 with Silverlight. I downloaded the IE6 and Silverlight installers from Microsoft's web sites and fortunately they both have command line options to allow them to run in "silent mode".
I put the two commands in a DOS batch script and ran it, but the IE6 installer requires makes an automatic computer restart so the question is how to resume the script and run the 2nd command (install Silverlight).
My batch file is very simple right now:
ie6setup.exe /Q
silverlight.exe /q
From what I know, batch files can't resume execution after restarting the computer. Is there a way to make them do that? of is there another way to accomplish what I need.
Thank you
Based on Tim's post which, when tested, appended "two" to the batch file resulting in a failure to find the batch label "onetwo", so amended to read & write the "current" variable from a seperate text file, leaving the batch file untouched;
#echo off
call :Resume
goto %current%
goto :eof
:one
::Add script to Run key
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /d %~dpnx0 /f
echo two >%~dp0current.txt
echo -- Section one --
pause
shutdown -r -t 0
goto :eof
:two
echo three >%~dp0current.txt
echo -- Section two --
pause
shutdown -r -t 0
goto :eof
:three
::Remove script from Run key
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /f
del %~dp0current.txt
echo -- Section three --
pause
goto :eof
:resume
if exist %~dp0current.txt (
set /p current=<%~dp0current.txt
) else (
set current=one
)
You could put the second command in a exclusive batch file, and add an entry to regedit to execute this batch file automatically upon Windows' start, making silverlight be executed after the computer restarts.
Have you heard of msconfig? On some systems the regedit PATH you are looking for is:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
But you may want to check that. If you want to make a batch file to write that key on the registry, you probably should take a look at this tutorial.
If you do the IE6 installation with the command ie6setup.exe /q /r:n then it won't reboot automatically (see this page for details). Then theoretically you could install SilverLight immediately, and then reboot afterwards; but there is a chance that the SL install will refuse due to the need of a reboot, but it won't hurt to try it...
I know its a bit old but this works amazingly:
#echo off
call :Resume
goto %current%
goto :eof
:one
echo two >>myfile.cmd
::REBOOT HERE
goto :eof
:two
echo resumed here
goto :eof
:resume
rem THIS PART SHOULD BE AT THE BOTTOM OF THE FILE
set current=one
#echo off
set "_RunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
rem./ :: if no argument was passed, this line will be ignored, but if so, it will be executed here == ^> & %~1
:1st_command
ie6Setup.exe /Q
shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :2nd_command\"" /f & goto :eof
:2nd_command
SilverLight.exe /Q
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :3rd_command\"" /f & goto :eof
:3rd_command
Skype-8.92.0.401.exe /VerySilent /NoRestart /SuppressMsgBoxes /DL=1 & goto :eof
It is possible to do it without creating or manipulating readings in additional files, just writing and reading in the key and using arguments passed in the execution to control the command necessary for the relevant execution, using goto command as an argument %1
#echo off
set "_RunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
rem./ if no argument was passed, below will be ignored, but if so, it will be executed here == ^> & %~1
:1st_command
mode con cols=50 lines=1 | title starting %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "stackoverflow.com" /new-tab
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :2nd_command\"" /f & goto :eof
:2nd_command
mode con cols=50 lines=1 | title starting %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "meta.stackexchange.com" /new-tab
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :3rd_command\"" /f & goto :eof
:3rd_command
mode con cols=50 lines=1 | title %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "www.amazon.com" /new-tab
goto :eof
Is there a command-line argument that would force firefox.exe to launch a new process for a particular URL regardless of whether another instance of firefox is already running?
If you have a second profile (like 'sidekick'), the following will launch a new Firefox process:
firefox.exe -no-remote -p sidekick
However, if that profile is already used by a current Firefox session, that will not work.
To create a new profile launch Firefox from the command line with the -P flag and create it.
firefox.exe -P
The OP ykaganovich adds in the comments (in Oct. 2020, three years later):
recent versions of Firefox (as of 2020) also have profile management UI available at about:profiles
I often need to close multiple instances, clear the cache and open multiple firefox windows when testing my changes after rebuilding my web application. I use firefox portable for this purpose to allow multiple instances. I have written below batch scripts which modify a FirefoxPortable installation if not yet modified, stop current firefox process and restart it. I normally have four instances running with a different executable name. One for my regular browsing, and the other three for testing web apps. Very useful when you want to test and certify your web app for current and previous versions of Firefox.
I may open three tabs in the same browser, but I tend to be paranoid when dealing with browsers. I prefer to clean and re-open a fresh instance of the browser for different applications before re-testing instead of F5 or Ctrl F5.
The script will run a separate firefox portable process with a separate process name and a separate profile.
Hope these help you. Feel free to use them. Please post back your modifications and bug fixes on this thread.
Install FirefoxPortable to folder named FirstFirefoxPortable (or any other appropriate name)
REM ==============
setlocal
set URL=%1
REM FirefoxPortable installation folder
set FIREFOX_PORTABLE_HOME=C:\portables\FirstFirefoxPortable
REM Name of the FirefoxPortable executable file
set FIREFOX_FILENAME_NOEXT=FirstFirefoxPortable
REM Name of the Firefox executable file within App/firefox
set FIREFOX_EXEC_NOEXT=firstfirefox
set FIREFOX_PORTABLE_EXEC=%FIREFOX_PORTABLE_HOME%\%FIREFOX_FILENAME_NOEXT%.exe
REM Name of the other profile folder.
set FIREFOX_PROFILE=firstprofile
set CLEAR_HISTORY=true
set CLEAR_CACHE=true
set CLEAR_SAVED_PASSWORDS=true
set CLEAR_SESSION=true
set WAIT_DURATION=4
set ADDITIONAL_WAIT_DURATION=2
if not exist %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini (
#echo off
echo.
echo.
echo Setting up Firefox Profile
echo.
echo.
pause
#echo on
echo [FirefoxPortable]>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo FirefoxDirectory=App\firefox>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo ProfileDirectory=%FIREFOX_PROFILE%\profile>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo SettingsDirectory=%FIREFOX_PROFILE%\settings>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo PluginsDirectory=%FIREFOX_PROFILE%\plugins>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo FirefoxExecutable=%FIREFOX_EXEC_NOEXT%.exe>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo AdditionalParameters=>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo LocalHomepage=>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo DisableSplashScreen=false>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo AllowMultipleInstances=false>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo DisableIntelligentStart=false>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo SkipCompregFix=false>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
echo RunLocally=false>>%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini
rem create dirs
pushd %FIREFOX_PORTABLE_HOME%
mkdir %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%
mkdir %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile
mkdir %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\settings
mkdir %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\plugins
popd
rem copy profile
xcopy /e %FIREFOX_PORTABLE_HOME%\App\DefaultData\profile %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile
copy /y %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%.ini %FIREFOX_PORTABLE_HOME%\FirefoxPortable.ini
rename %FIREFOX_PORTABLE_HOME%\FirefoxPortable.exe %FIREFOX_FILENAME_NOEXT%.exe
rename %FIREFOX_PORTABLE_HOME%\App\Firefox\firefox.exe %FIREFOX_EXEC_NOEXT%.exe
)
rem check if firefox is running
REM tasklist /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe" 2>NUL | find /I /N "%FIREFOX_FILENAME_NOEXT%.exe">NUL
REM if "%ERRORLEVEL%"=="0" (
REM echo Firefox running
REM taskkill /t /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
REM ping -n 4 127.0.0.1 > NUL
REM tasklist /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
REM echo retrying killing Firefox
REM taskkill /f /t /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
REM ping -n 2 127.0.0.1 > NUL
REM taskkill /f /t /FI "IMAGENAME eq %FIREFOX_EXEC_NOEXT%.exe"
REM ) else (
REM echo Firefox not running.. starting..
REM )
taskkill /t /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
ping -n %WAIT_DURATION% 127.0.0.1 > NUL
echo ==== try killing
tasklist /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
tasklist /FI "IMAGENAME eq %FIREFOX_EXEC_NOEXT%.exe"
taskkill /t /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
taskkill /t /FI "IMAGENAME eq %FIREFOX_EXEC_NOEXT%.exe"
ping -n %ADDITIONAL_WAIT_DURATION% 127.0.0.1 > NUL
echo ==== retry killing forcefully
tasklist /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
tasklist /FI "IMAGENAME eq %FIREFOX_EXEC_NOEXT%.exe"
taskkill /f /t /FI "IMAGENAME eq %FIREFOX_FILENAME_NOEXT%.exe"
taskkill /f /t /FI "IMAGENAME eq %FIREFOX_EXEC_NOEXT%.exe"
REM clear everything - delete profile
REM del /f /s /q %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\*
REM rmdir %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\
REM mkdir %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\
REM clear all sqlite files
rem for /d %%x in (%FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\*) do del /q /s /f %%x\*sqlite
if "%CLEAR_HISTORY%"=="true" (
echo.
echo Clearing History
echo.
rem clear history (Bookmarks, browsing and download history)
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\places.sqlite*
rem clear form history (Saved form data)
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\formhistory.sqlite*
)
if "%CLEAR_SESSION%"=="true" (
echo.
echo Clearing browsing session
echo.
rem clear previous browsing session
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\sessionstore.js
)
if "%CLEAR_SAVED_PASSWORDS%"=="true" (
echo.
echo Clearing saved passwords
echo.
rem clear saved passwords
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\logins.json
)
if "%CLEAR_CACHE%"=="true" (
echo.
echo Clearing cache
echo.
rem clear permissions (Permission database for cookies, pop-up blocking, image loading and add-ons installation.)
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\permissions.sqlite*
rem clear content preferences (Individual settings for pages.)
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\content-prefs.sqlite*
rem clear cookies
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\cookies.sqlite*
rem clear cache
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\cache2\*
rem clear offline cache
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\OfflineCache\*
rem clear DOM Storage
del /q /s /f %FIREFOX_PORTABLE_HOME%\%FIREFOX_PROFILE%\profile\webappsstore.sqlite*
)
if "%URL%"=="" (
set URL=www.google.com?q=DidYouPassTheURLArgument
)
#echo on
start /MAX "%FIREFOX_FILENAME_NOEXT%.exe" %FIREFOX_PORTABLE_EXEC% -P "%FIREFOX_PROFILE%" -no-remote -new-tab %URL%
endlocal
REM ==================
Script for opening firefox for the second app. It is the same script as above.
Copy and Save in a separate file e.g. secondfirefox.bat. Install FirefoxPortable in another folder e.g. C:\portables\SecondFirefoxPortable. Change the variables in secondfirefox.bat to point to the other portable firefox install folder.
setlocal
set URL=%1
REM FirefoxPortable installation folder
set FIREFOX_PORTABLE_HOME=C:\portables\SecondFirefoxPortable
REM Name of the FirefoxPortable executable file
set FIREFOX_FILENAME_NOEXT=SecondFirefoxPortable
REM Name of the Firefox executable file within App/firefox
set FIREFOX_EXEC_NOEXT=secondfirefox
set FIREFOX_PORTABLE_EXEC=%FIREFOX_PORTABLE_HOME%\%FIREFOX_FILENAME_NOEXT%.exe
REM Name of the other profile folder.
set FIREFOX_PROFILE=secondprofile
REM --- snip ---
---- Update ----
Bug fixes - corrected the profile path.
Separated out variable for clear passwords. Remember password for the login page of my web app. Less typing.
---- Update ---- 2014-10-01
Removed the need to manually rename the FirefoxPortable.exe file. The script does it on first run of FirefoxPortable installation.
---- Update ---- 2014-11-09
Changes to allow updating by running the FirefoxPortable installer. When this batch asks you to overwrite the prefs and bookmarks, type N. This will preserve bookmarks and some settings.
Yes, as detailed in Firefox Command Line Arguments:
firefox -new-window
Edit: re-reading you actually said "process", in which case no, I don't think you can.
Starting a new process (instance) is done by
-new-instance
Open new instance, not a new window in running instance, which allows multiple copies of application to be open at a time.
firefox -new-instance -P "Another Profile"
Note: Not available for Windows, see bug 855899.
If you're on a Mac you can use this command to open a new instance with a fresh blank profile each time:
open -n -a Firefox.app --args -profile `mktemp -d /tmp/fx-profile.XXXX` -no-remote -new-instance