Script to Backup CPF v2.4 firewall settings

The folder and the subfolder hold the current ruleset and the previous set, respectively, just to give us a better fallback postition.

cheers, and glad to hear it worked!

ewen :slight_smile:

Does the destination matter? Yes, - the sense is storing your backups on the drive that are backing up is what??? LOL

The REG file can be transpported anywhere!

ewen :slight_smile:

I guess my question was, are three different scripts for different file destinations really needed? Why not just one script with a known save location (whatever that might be) with the statement that the user needs to move the file off-system to another drive.

I totally get the point of not having it on the drive that’s gonna crash. I may not know much (and I am from Texas…), but I know THAT much. Wasn’t born yesterday. :wink: LOL

LM

Rotty wrote the three versions to try and satify the differing requests he received after the wrote the first, palin vanilla one. We have added some hints on how to modify (e.g by using %1 to represent a pramater passed at the command line, etc.) but a lot of people’s collective eyes glazed over when we started talking DOS. LOL

I agree, one straight forward version would be best, but its only best for those who can modify to suit their explicit needs.

Cheers LM,
Ewen :slight_smile:

Hey Rotty,

Have a look at

https://forums.comodo.com/index.php/topic,4128.msg31222.html#msg31222

Your scripts been adapted to backup the Comodo Backup jobs and settings.

Thanks again,
Ewen :slight_smile:

The scripts can be fixed with a few quotation marks. This is what I did:

@echo off cls echo ***************************** echo The settings are backed up to %ALLUSERSPROFILE%\CPFBackup\CPFRUles.REG echo Merge the "CPFrules.reg" file back, to restore settings echo ***************************** echo To start press enter. To quit press the "x" button on this window pause >nul:

cls
if not exist “%ALLUSERSPROFILE%\CPFBackup” goto :new
goto :archive

:archive
echo Clearing oldest backup - please wait
del “%ALLUSERSPROFILE%\CPFBackup\Prior\CPFRUles.REG” >nul:
echo Storing previous backup - please wait …
copy “%ALLUSERSPROFILE%\CPFBackup\CPFRUles.REG” “%ALLUSERSPROFILE%\CPFBackup\Prior\CPFRUles.REG”
echo Archiving current rule set - please wait …
REGEDIT /E “%ALLUSERSPROFILE%\CPFBackup\CPFRUles.REG” “HKEY_LOCAL_MACHINE\SYSTEM\Software\Comodo\Personal Firewall”
goto :end

:new
cls
echo.
echo Creating folders - please wait …
echo.
md “%ALLUSERSPROFILE%\CPFBackup”
md “%ALLUSERSPROFILE%\CPFBackup\Prior”
echo Archiving registry keys - please wait …
REGEDIT /E “%ALLUSERSPROFILE%\CPFBackup\CPFRUles.REG” “HKEY_LOCAL_MACHINE\SYSTEM\Software\Comodo\Personal Firewall”
copy “%ALLUSERSPROFILE%\CPFBackup\CPFRUles.REG” “%ALLUSERSPROFILE%\CPFBackup\Prior\CPFRUles.REG” >nul:
goto :end

:end
echo DONE!!!
echo Press any key to end
pause >nul:

I tested the script and I had a few problems with paths. I had thought the scripts included the quotes from Sandman’s post, but it did not. I added the necessary double quotes. I replaced %…% by %HOMEPATH% in order to save to my home path (AllUsers should seldom be used to store data IMO). Then I created a global environment variable for the path, so that the only difference between the different versions is in line 3: just replace “set CPFB=%HOMEPATH%” with “set CPFB=%SYSTEMROOT%”. I added the last exit so that the window closes automatically.

It works. At least for me!


@echo off
cls
set CPFB=%HOMEPATH%
echo *****************************
echo The settings will be backed up to %CPFB%\CPFBackup\CPFRUles.REG
echo Merge the "CPFrules.reg" file back, to restore settings
echo *****************************
echo To start press enter. To quit press the "x" button on this window
pause >nul:

cls
if not exist "%CPFB%\CPFBackup" goto :new

:archive
echo Clearing oldest backup - please wait
del "%CPFB%\CPFBackup\Prior\CPFRUles.REG" >nul:
echo Storing previous backup - please wait ...
copy "%CPFB%\CPFBackup\CPFRUles.REG" "%CPFB%\CPFBackup\Prior\CPFRUles.REG" >nul:
echo Archiving current rule set - please wait ...
REGEDIT /E "%CPFB%\CPFBackup\CPFRUles.REG" "HKEY_LOCAL_MACHINE\SYSTEM\Software\Comodo\Personal Firewall"
goto :end

:new
cls
echo.
echo Creating folders - please wait ...
echo.
md "%CPFB%\CPFBackup"
md "%CPFB%\CPFBackup\Prior"
echo Archiving registry keys - please wait ...
REGEDIT /E "%CPFB%\CPFBackup\CPFRUles.REG" "HKEY_LOCAL_MACHINE\SYSTEM\Software\Comodo\Personal Firewall"
copy "%CPFB%\CPFBackup\CPFRUles.REG" "%CPFB%\CPFBackup\Prior\CPFRUles.REG" >nul:
goto :end

:end
echo DONE!!!
echo Press any key to end
pause >nul:
exit

It didn’t exit by itself… :wink:

Ok, my fault. The final exit is useless. I needed the exit because I ran cmd, then from inside the dos box I ran manually the batch. Then of course I would need en exit to close the dos box. Silly me. Would anyone have a smiley that slaps itself in the face?

The other mods should be ok, though. I feel the trick of using an intermediate environment variable is useful. I would have included a way to let the user choose at execution time where to put the backup, but to do this I would need XP-specific syntax (extensions to the SET command).

I can chase you… dunno if I catch you… :THNK

(:TNG) (:AGY)

Hey Frederic,

There’s an easier way to achieve this, rather than fiddling with the SET command.

The XP command interpreter still supports command line input parameters (%1, %2, etc.). If we assume that we always want the backup to be stored in a folder called “cpfbackup” and we only want to vary the drive that this folder is created on, if we replace all instances of “%CPFB%” with “%1” and invoke the batch file with the command “cpf_bu f:”, the output of the batch file will be redirected to drive F:, or whatever we specified when invoking the batch.

There’s another really handy command you can use with this (or any other) batch file - AT.

We could create another batch file that triggers the cpf_bu batch file at a predetermined time every day (or every week). A sample of this is below in red. The sample assumes that we are calling a batch file called “cpf_bu.bat” located in the root of drive C: and we want it to run at 6:41:00AM. The assumptions have been made primarily 'cause I’m too lazy to figure anything else out. LOL. you’ll need to remember to replace the “[ at ]” with the real at symbol (as opposed to the at command).

Now I don’t know where I’m at. LOL


[ at ] echo off
at 6:41:00 c:\cpf_bu.bat


We unfortunately can’t combine the “at” command with the input variable, as it seems to cease parsing at the filename, so we would need to pre-modify the batch file to contain the required destination path.

To have this run the CPF backup every day, include the above line in a batch file and place the batch file in STARTUP, win.ini (XP will still read this) or somewhere that is autoexecuted on system startup.

If you are going to run this to autobackup the rulesets, I’d modify the cpf_bu.bat script to make a further iteration (current - prior - oldest). This is just in case the rulesets get stuffed up and we have overwritten our good rules. Next time we boot, out good prior rulesset woudl be overwritten and wehave no way back. With a third iteration, we’ve at least got one reboot to move the good backup out of the way. Just a thought.

Hope this helps,
Ewen :slight_smile:

I don’t know why, I felt that using command line parameters wasn’t a good idea. But you are right, since the parameters could be hard coded in the shortcut, your way of doing it is simpler. But we’d still have to document the fact that the destination can include environment paths such as HOMEPATH.

If anyone wants the script updated, i can edit my original post.

Admins are welcome to up date my first post if necessary (-: . I will have differing amounts of work over the next 3 years so i may not visit for a week or two occasionally.

Learning C++ to, may port this program to C++ if it turns out to be a good language for the aim of this program and if COMODO have not implemented the scripts functionality into the program.

Make it really shine, have proper archiving, could put an auto run/ scheduling feature in and all sorts of stuff. I don’t program Batch for work or learning so hence anything new to be added has to be researched and learnt then to use a language that i know and are using in other areas anyway.

cheers, rotty

Porting it to C++ or any other compiled language would not be a good idea IMO (except as a way to learn how to do it).

First of all, I think you have more chances to find users able to understand a DOS batch than a c++ source (at least in the Windows world). I don’t think you would have got so many corrections as you got here if you had originally posted your tool in c++.

Second, a 3rd generation language implies a compiler to deploy any correction or evolution. Not everybody has a compiler and knows how to use it.

Third, if someone posted a new compliation supposedly with corrections or new features, it would imply taking measures to ensure this new version isn’t actually a trojan or doesn’t contain a virus.

And fourth, this kind of feature should be directly included in CPF, the external tool is only a temporary solution until then.

OTOH, using a more evolved language would allow more user-friendly features. I don’t know enough VBscript, but maybe it could be done with it…

Hopefully Comodo will put in a save settings option VERY soon… ;D

davitef: Yes you named the main reasons why we choose batch files instead of any compiled programming language.

Turns out I’m not learning c++ anyway (-:

I would NEVER put a virus in something i write, the main reason being that to test it i would have to run it on my own PC (:TNG) . And secondly morally wrong. And thirdly i have no imaging software (:TNG). Fourthly i don’t have time and could not be bothered (Got better things to do).

regards, rotty

I know question is pretty lame. My dos knowledge about making scripts is close to zero.

How do I copy and paste the code posted to make a executable?

It’s only scary the first time!

  1. Highlight the code and press CTRL-C to copy it to the clipboard.
  2. Open NOTEPAD
  3. With Notepad open, click inside the notepad window and press CTRL-V to paste the copied code.
  4. Make whatever modifications you want to suit your environment.
  5. Click FILE - SAVE AS
  6. Change the “Save as type” to “All files”
  7. Give your script file a name and make sure it ends in".BAT" (Note the full stop before the B-A-T).

Congrats, you have just saved your first batch file.

Hope this helps,
Ewen :slight_smile:

Rotty:

Sorry, I was not clear enough, I did not mean you would voluntarily put a virus. Once you post an executable, someone else will post an evolution and somewhere in the chain of posts someone might post (voluntarily or not) a contaminated version.

Remember that you may very well be unaware that you are hosting a virus (even if you have a good and up to date anti virus). Virus almost always have incubation periods during which they only disseminate and contaminate other systems without doing any harm (just like biological viruses do). So your system (or mine or the system of any other subscirber) may very well harbor an unknown yet malware.

MFB:

Actually, I’d advise you to download using one of the links below the original post. Here is why: This comodo forum automatically transforms some characters. So that the first line of the script has been changed (I think this is the only modification). This modification doesn’t change results of the script, only it’s visual behaviour. If you decide to copy-paste the script, you should replace [ at ] with the at sign (the one that is used in e-mail addresses). You should remove the folowing space too so that the at sign is immediately followed by echo off, like in the following example (except that I used a dollar sign instead of the at sign):
$echo off