# Batch file compatable with win95, 98, me, nt, xp



## aewarnick (Sep 3, 2002)

Is it possible to create a batch file that will place a screen saver or a font in the correct place for any operating system with one "universal" batch file?

If so, can someone help me create it?


----------



## Rockn (Jul 29, 2001)

Sure...you need to write the batch file to check which OS is on the system and call the appropriate section for each.


----------



## aewarnick (Sep 3, 2002)

Great! I think I'll work on finding out what to write and how to write it. Would you have any sites in mind that could help me write the batch file?


----------



## aewarnick (Sep 3, 2002)

I have been using this install maker program and it makes these files that should be very little, pretty big. That is why I want to use batch files instead to install screen savers and fonts.


----------



## Rockn (Jul 29, 2001)

To what end exactly? Is this for new installations of an OS or just general messing around?


----------



## aewarnick (Sep 3, 2002)

I created my own screen savers and made a web page that uses Bangle font. Not everyone has the Bangle font. I just want easy installations for everyone.


----------



## MacFromOK (Mar 19, 2001)

_____________________________________________

For what it's worth...

The only font I can remember adding to Windows
95 was "webdings" (a buddy sent it to me), and
just copying it to the font directory didn't work.

I had to downloaded and run a self-installing EXE
to get webdings workin'... 

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

That is good to know. Are the fonts also stored somewhere else like the registry?


----------



## MacFromOK (Mar 19, 2001)

Apparently so. Mine (Windows 95) are in:

```
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts
```
Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

Maybe I can put a reg entry into my batch file to update the registry also. Do you think?


----------



## MacFromOK (Mar 19, 2001)

I kinda doubt it...


----------



## MacFromOK (Mar 19, 2001)

Well, I'm wonderin' now... check out this link:

http://www.ericphelps.com/batch/samples/username.txt

Ya might also do a search at www.google.com using:

*+"batch file" +"registry"*

Include the plus signs (+) and quotes. 

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

Found this somewhere:

In Win9x, this does it:
REGEDIT /E FILENAME KEYPATH

That is all I could find. Everything else used this command in the batch file to run a .reg file outside of the batch file: regedit /s filename.reg

I was thinking that maybe there is a way to specify the contents of a .reg file in the batch file and have it save a .reg file somewhere on the computer and then use that command.

For example:

Maybe put this in the batch file. . .
Then have a command to take that information and save it as a .reg file?

REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Fonts]
"Bangle Bold (TrueType)"="BANGB___.TTF"
"Bangle Italic (TrueType)"="BANGI___.TTF"
"Bangle Normal (TrueType)"="BANGN___.TTF"


----------



## MacFromOK (Mar 19, 2001)

Well, ya can always give it a try on your system, just make
a registry backup first...

Coupla more ideas...

What language is your screensaver written in? Any chance of
checking and installing the font (if needed) from the screensaver
code? That would also take care of the user accidentally deleting
the font.

Or have ya tried finding the font in an executable install? Ya
could prolly run that from your setup batch file...

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

I do not want to use the setup file at all because it is too big compared to the batch file I am making.

The problem with the above mentioned system is that I don't know how to do it. Is it possible to put text into a batch file and then export that text to a new text document file and save it to the hard drive?

I know if I could get that far the rest would be cake. But I don't know if it is possible to do that or not.


----------



## MacFromOK (Mar 19, 2001)

Yes, you can write text to a file from inside a batch file.

To create or overwrite a file:

*echo This is a test... > c:\test.txt*

To append to an existing file (creates the file if it doesn't exist):

*echo This is a test... >> c:\test.txt*

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

Perfect! That is exactly what I want!!! I hope it works.


----------



## aewarnick (Sep 3, 2002)

2 Problems:

1. Can't get it to take anything more than the first line after echo.
2. I don't want it to show up when it runs. I tried >nul but that didn't work. I also tried "echo off REGEDIT4" but that didn't work either.

echo REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Fonts]
"Bangle Bold (TrueType)"="BANGB___.TTF"
"Bangle Italic (TrueType)"="BANGI___.TTF"
"Bangle Normal (TrueType)"="BANGN___.TTF" > d:\test.reg


----------



## aewarnick (Sep 3, 2002)

I may have solved problem 1 but I would like an easier way if there is one than this:

Putting this after each and every line: >> d:\test.txt

Also, how do I create a blank space?


----------



## MacFromOK (Mar 19, 2001)

A batch file executes one line at a time.

Each line added to a file must have its' own echo line, and
only use the single *>* on the first line (it overwrites the
file, remember?). Use *>>* on the rest. 

You can turn off ECHO by using:

*@ECHO OFF*

as the top line of the batch file.

Also, be sure you don't run over 128 chars per line. That's
the standard DOS command line buffer size. 

Cheers, Mac


----------



## MacFromOK (Mar 19, 2001)

Sorry, we were posting together.

To add a blank line use *echo.* like this:

*echo. >> c:\test.txt*

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

All set. It worked perfectly! Thanks a lot Mac.


----------



## aewarnick (Sep 3, 2002)

Just to finish off this thread. . . here is what I came up with:

I will use this command structure to identify the O.S.
@echo off
ver | find "Windows 95" >nul
if not errorlevel 1 goto 9x
ver | find "Windows 98" >nul
if not errorlevel 1 goto 9x
ver | find "Windows Me" >nul
if not errorlevel 1 goto Me

Here is how I create the registry file and save it to the disk:
echo REGEDIT4> Bangle\Bang_9x.reg
echo.>> Bangle\Bang_9x.reg
echo [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Fonts]>> Bangle\Bang_9x.reg
echo "Bangle Bold (TrueType)"="BANGB___.TTF">> Bangle\Bang_9x.reg
echo "Bangle Italic (TrueType)"="BANGI___.TTF">> Bangle\Bang_9x.reg
echo "Bangle Normal (TrueType)"="BANGN___.TTF">> Bangle\Bang_9x.reg

Thanks Mac, you have been a lot of help to me!


----------



## MacFromOK (Mar 19, 2001)

You're welcome, and I'm glad ya posted your finished
code - I learned some stuff too. 

BTW, one thing to remember about errorlevels in batch files:
An errorlevel will trigger lesser errorlevel checks. For example,
if there's an "errorlevel 3", it will trigger all these:

if errorlevel 3 echo 3
if errorlevel 2 echo 2
if errorlevel 1 echo 1
if errorlevel 0 echo 0

You can deal with this a couple of ways. If using "goto"
just check for the higher levels first (no need to check
for zero since it's the only one left):

if errorlevel 3 goto label_3
if errorlevel 2 goto label_2
if errorlevel 1 goto label_1
goto label_0

If NOT using "goto", ya gotta make sure it's exactly at
the errorlevel ya want:

if errorlevel 3 if not errorlevel 4 echo Errorlevel 3
if errorlevel 2 if not errorlevel 3 echo Errorlevel 2
if errorlevel 1 if not errorlevel 2 echo Errorlevel 1
if errorlevel 0 if not errorlevel 1 echo Errorlevel 0

Wasn't sure if ya knew this or not (and your code
is OK), just thought I'd throw it in... 

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

Actually I haven't studied up on what errorlevel does at all. I just learned how to write batch files 2 days ago. I just learned to write html docs about a week ago. I am learning a lot of things in a short amount of time.

Could you help me understand errorlevel, Mac?


----------



## MacFromOK (Mar 19, 2001)

The DOS errorlevel is set by a program when it exits.
It may be set to different numbers (0 - 255) depending
on what happened in the program (numbers used are up
to the programmer). It gives a way to check what has
happened - if there was an error or the desired results
weren't accomplished, or to verify that it worked OK.

For example, your code:
*
ver | find "Windows 95" >nul
if not errorlevel 1 goto 9x
*
sets the errorlevel to zero if the string is found (and
jumps to the "9x" label), or sets it to greater than
zero if not found (and continues to the next line).

CHOICE.COM is a good errorlevel example - it gets
the errorlevel number from the order of the choices
listed left to right:

```
@ECHO OFF

:START
  CLS
  echo.
  echo Press a key (A B or C) or  press X to exit...
  rem -- The errorlevels are set by the order of the choices --
  CHOICE /c:abcx /n > nul
  CLS
  echo.
  if errorlevel 4 goto END
  if errorlevel 3 if not errorlevel 4 echo You pressed C...
  if errorlevel 2 if not errorlevel 3 echo You pressed B...
  if errorlevel 1 if not errorlevel 2 echo You pressed A...
  echo.
  rem -- CHOICE defaults to Y/N if you don't specify choices --
  CHOICE Continue
  if errorlevel 2 goto END
  goto START

:END
  CLS
  echo.
  echo Goodbye!
  echo.
```
If you have a later version of windows that doesn't
have CHOICE.COM (Win9x has it), you can get it here:

http://www.geko.ch/tech-tips.htm#Batch

It's also included on the DOS 6x supplemental diskette
that's available (as a free download) from MS.

Hope this gives ya an idea how errorlevels work. 

Cheers, Mac


----------



## aewarnick (Sep 3, 2002)

That definately did help. Thanks.


----------



## noveltech (Sep 29, 2002)

If you don't get that to work; GLPro creates screen savers and will use your fonts within the finished SS program. Will not need to have the font on client machine.

Will work on most 32 bit OS. NT


----------



## aewarnick (Sep 3, 2002)

It does work and this project is for 2 specific, individual things. To place the s.s. in the s.s. folder and for installing the bangle font for web page viewing.


----------

