Some batch commands that I need help with

bielius

Posts: 217   +17
Hey, I have to do this project at school, I have to make some .bat files that execute different things.
what I have to do:
4. make a batch file called show_info.bat that

clears the screen,
then displays the current System version,
then displays the date followed by the time,
then displays the computer name,
then displays the user name,
then displays the user home directory,

This is what I have so far:

CLS
VER
%date% %time%
%computername%
%username%
%homedirectory%
cmd

I know that this might not(IS NOT) be right. But when for example cmd executes %username% it displays the username and tries to use my username as a command, which is not recognised. My question is, how do I just display those things, instead of "pasting" them in and using as a command?
oh and what is the command which displays user home directory?
Thank you so much!
 
You need an echo in front of those to just display the result - and it's %homepath% . You can see your variables to work with by typing "set" at a command prompt.
 
Running cmd will open another instance of command-line. If you want cmd to automatically do anything when it opens, you will need to give cmd parameters.

LNCPapa is correct, if you want to display a specific environment variable to screen, you will need to use the echo with the variable as a parameter.

Example:
ECHO %PATH%
CMD /K "C:\RUNTHIS.BAT"

Type "HELP" for a list of commands. If you want help with a specific command such as ECHO, type "HELP ECHO".
 
But if I do not type in CMD at the end, the whole cmd window will open up and dissapear immediately.
 
LNCPapa, this is what I am at right now:
CLS
ECHO
VER
ECHO
%date% %time%
ECHO
%computername%
ECHO
%username%
ECHO
%homedirectory%
ECHO
%homepath%

pause

And it still gives me those ugly "is not recognized as an internal or external command, operable program or batch file." lines.
Now I have tried with ECHO, ECHO ON and ECHO OFF and is still does not make any difference. What I need is just lines with the answer without anything else.
Sorry, I am still a newb at this, maybe I should go and read some guides. On that topic, maybe you guys know of a good guide on command line commands and such?
 
The command and the parameter for the command needs to be on the same line.

Example:
dir /s *.avi

The command dir shows the directory listings of the current folder. The /s parameter includes all subfolders and the *.avi parameter only list the files that end with avi.

"Echo" by it self is an incomplete command.
"Echo." with a period behind echo will display an empty line. This will separate text, much like the empty line between paragraphs.
"Echo" followed by any text or variable will display the text or variable value.

If the very first line of your bat file is "Echo off", the only lines you will see are the ones you echo to screen.
 
Being that you say this is a school project I'm trying my hardest to not just hand you the completed code... perhaps you should use the help command a bit more. For instance, you could have typed in "help echo" at a command prompt to get proper syntax info about that command. I personally feel everyone who uses computers for more than just surfing the web and typing up papers should learn how to create simple batch files. Nothing too complicated, but enough to have a decent foundation and not be scared off when they see a bit of code.
 
Okay, So I got this. the problem now being is, that I get the answer f.ex. "28.06.2012" as the %Date%, but it still says Is not recognised as an internal... bla bla bla. I really do not know what to do next. If you could give me one working line of the code, I would work my way with it and actually learn what is going on.

Echo off


VER

%date%

%time%

pause
 
Code:
@echo off
ver
echo %date%
echo %time%
pause

The echo command tells it to display the result to the screen (or if you are redirecting it, elsewhere).
 
Code:
@echo off
cls
ver
echo Current Date and Time: %date% %time%
echo Computer Name: %COMPUTERNAME%
echo User Name: %USERNAME%
echo User Home Directory: %USERPROFILE%
pause
 
I think your confusion is coming from not actually understanding what you are typing. The items surrounded by % are environment variables. They store data in a way that makes it convenient for us to access and use.

cmd, VER, CLS, those are actual commands that tell the computer we want it to *do* something.

So we need to tell the computer to *do* something *with* those environment variables. You've been given the ECHO command already, and it would benefit you greatly to look it up and learn what it tells the computer to *do*. Then you should be able to figure out how to use it with the environment variables to present the data in a meaningful script.

Just coming to a forum and asking for code is not going to help anyone - not you, not your school, and certainly not your future employer when they realize you didn't learn basic scripting because someone on a forum gave you the answer. Not trying to be mean, but we have a lot of "paper" diplomas out in the wild and it's a shame.
 
Back