【发布时间】:2020-09-10 06:57:22
【问题描述】:
目标是使用批处理脚本执行以下操作:
- 从 Windows 机器中提取主机名。
- 对主机名值应用 sha256 哈希(从步骤 1 获得)。
我系统的主机名是:W0000000000ZQ
我的批处理脚本如下所示:
@echo off
hostname>hostname.txt
CertUtil -hashfile hostname.txt SHA256 //<- this is generating wrong sha256 string because
// the above generated file contains CRLF and a new line
// screenshot of this file provided below.
CertUtil -hashfile hostname-manual.txt SHA256 //<- this is generating correct sha256 string because
// i manually created this file and pasted hostname
// only (W0000000000ZQ) without CRLF and new line.
// screenshot of this file provided below.
主机名.txt:
主机名-manual.txt
脚本的输出:
您能否建议如何从“hostname.txt”中删除 CRLF 和换行符,以便 Certutil 选择正确的字符串来生成 sha256 值。
【问题讨论】:
-
有点挑剔:你没有得到 CRLF 和换行符;你只是得到一个 CRLF,它 是 换行符。
-
试试
< nul > "hostname.txt" set /P ="%ComputerName%"...
标签: windows batch-file newline