Discussion Locked

echo command in batch file misbehaving

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a batch file that I need to run in Windows 2000 and Windows 98 machines. Part of the bach file (in theory) captures the machine name and writes it to a log file via an echo command. The problem is, on 98 machines, sometimes it logs the machine name and other times it logs the words "echo is off" instead. The same PC will log it different ways. I have found no pattern as to why it will record the machine name one time and the words "echo is off" other times. The batch file is below. I would appreciate any help...

NET CONFIG | FIND /I "Computer Name" > %temp%.\netconf$.bat
echo >> computer.bat r:\tammy\cae\winset COMPUTERNAME = %%2
call %temp%.\netconf$.bat
echo %computername% >> r:\tammy\cae\done\w98.txt
GOTO END

10 replies

by ann777

There's nothing wrong with the batch file.

On the computers where the return is sometimes "echo is off," I'd look for another program or batch turning off echo in either the netconfig$.bat, or the Startup folder, or with the TSRs.

You might want to add an "echo on" line to the end of netconfig$.bat so that when the batch reaches the next line, it should perform that write to the text file without echoing "echo is off."

by opatzg9

Anna 's is right there that another pc has the echo is off, try using the @ symbol in front of the echo, that normally leaves you without the "echo" showing up as well on the line. So do the following:
NET CONFIG|FIND/I"Computer Name">%temp%.\netconf$.bat
@echo on
@echo >>Computer.bat r:tammy\cae\winset Computername = %%2
Call %temp%.\netconf$.bat
@echo %computername%>>r:\tammy\cae\done\w98.txt
GOTO END

by rezo247

I assume what you are dealing with may be a login script.

%computername% is provided by the NT OS only. To get it running on Windows 9x, I suggest you search for the PUTINENV.EXE tool (available over the Internet, just enter the name in any search engine).

the tool does not work with NT, so the code to invoke it is like following:

if [%os%]==[Windows_NT] goto rezo247
%0\..\putinenv L
:rezo247

Now you can make use of %username% and %computername% or other such variables like youcan in NT. Use winset.exe from the Windows 98 CD to make the variables permanent if you wish, otherwise they get lost as soon as you close the calling batch or command shell.

Save putinenv.exe at the same place where you save the calling batch file.

Another sample script you could prepend to your script is:

if "%OS%"=="Windows_NT" goto winnt
if exist %windir%\putinenv.exe goto rezo247
copy \\\NetLogon\putinenv.exe %windir%\*.*
:rezo247
%windir%\putinenv.exe L
%LogonServer%\NetLogon\Winset USERNAME=%USERNAME%
%LogonServer%\NetLogon\Winset COMPUTERNAME=%COMPUTERNAME%
%LogonServer%\NetLogon\Winset LOGONSERVER=%LOGONSERVER%
:winnt

I am not happy with the need to use \\, but the only way I can think of to eliminate it is to copy PUTINENV.EXE to all your W9x machines, outside of a logon script.

by tech_know

How to I get putinenv.exe? I have looked all over the web and cannot find where to download it.

This discussion is closed to new replies.