目标是使用批处理脚本执行以下操作:
- 从Windows机器中提取主机名。
- 对主机名值(从步骤1获取)应用sha256哈希。
我的计算机主机名是: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.
hostname.txt:
hostname-manual.txt:
脚本输出:
请建议如何从“hostname.txt”中删除CRLF和换行符,以便Certutil选择正确的字符串生成sha256值。
< nul > "hostname.txt" set /P ="%ComputerName%"
... - aschipfl