使用许多命令创建.Bat

时间:2018-10-28 15:24:01

标签: windows batch-file cmd

我关心的是“如何创建.bat文件,它将启动几个命令并将完成的结果保存到HTML文件中”

我有Windows(CMD)命令的下一个列表:日期,时间,主机名,网络帐户,网络用户,网络组。

例如:

当我键入:

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

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

我收到:

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.

第一个问题是-我没有收到命令名称(在此示例中,该名称应为“ Net Accounts”)

第二个问题是-我只对第一个命令获得结果。 -已解决

我做错了什么?

1 个答案:

答案 0 :(得分:1)

如果您输入:

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

您将在补丁“ C:\ Users \ PeKa \ Documents \”中创建一个名为“ document.HTML”的文件,其内容将是这样的一行:

  

净帐户

发生这种情况的原因是因为 echo 用于显示消息。我想您真正想要的是将网络帐户结果通过管道传输到.html文件以及网络组,顺便说一句,该网络只能使用在Windows域控制器上。

为使代码正常工作,只需消除回声即可。而已。在这里,加上评论:

@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

相同的脚本,没有注释:

@echo off

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

pause