Creating .Bat with many commands

Nickk

New Member
#1
My concern is "how to create .bat file which will launch a couple of commands and save completed result into a HTML file"

I have next list of Windows (CMD) commands: Date, Time, Hostname, Net Accounts, Net Users, Net Group.

For example:

When i type:
Mã:
Echo Net Accounts > C:\Users\PeKa\Documents\Document.HTML

Echo Net Group >> C:\Users\PeKa\Documents\Document.HTML
I receive:
Mã:
Force user logoff how long after time expires?:       Never
Minimum password age (days):                          0
Maximum password age (days):                          42
Minimum password length:                              0
Length of password history maintained:                None
Lockout threshold:                                    Never
Lockout duration (minutes):                           30
Lockout observation window (minutes):                 30
Computer role:                                        WORKSTATION
The command completed successfully.
1-st problem is - I don't receive a command name (for this example it should be "Net Accounts")

2-nd problem is - I gain result only for the first command. - Solved

What have I done wrong?
 

Admin

Administrator
Thành viên BQT
#2
If you type:
Mã:
Echo Net Accounts > C:\Users\PeKa\Documents\Document.HTML
You will create a file called "document.HTML" in the patch "C:\Users\PeKa\Documents\", which content will be a line like this:
The reason for that to happen is because echo is used to display messages. I guess that what you really want is to pipe net accounts results to a .html file, as well as for net group, which, by the way, can be used only on a Windows Domain Controller.

For your code to work, just eliminate echo. That's it. Here, with comments:

Mã:
@echo off
rem Everytime you see a line that starts with REM or ::, it is a comment and won't be executed.
rem echo off will only type on the screen the relevant information, without the need to call the patch each time.

rem This will pipe the result of Net Accounts and Net Group execution to a file.
rem The use of > instead of >> will rewrite the whole document, if it exists.
Net Accounts > C:\Users\PeKa\Documents\Document.HTML
Net Group >> C:\Users\PeKa\Documents\Document.HTML

rem A pause just before your script ends will allow you to review any in screen message before it closes.
rem However, if an error takes place, the pause command will not avoid the script to close.
pause
The same script, without comments:
Mã:
@echo off

Net Accounts > C:\Users\PeKa\Documents\Document.HTML
Net Group >> C:\Users\PeKa\Documents\Document.HTML

pause
 

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top