Reputation: 1997
Goal is to do the following using batch script:
My system's hostname is: W0000000000ZQ
My batch script looks like this:
@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
Output from the script:
Can you please suggest how to remove CRLF and a newline from "hostname.txt" so that Certutil will pick correct string to generate sha256 value.
Upvotes: 3
Views: 2087
Reputation: 17678
The following saves the hostname to a file without the trailing CRLF.
for /f %%h in ('hostname') do (>hostname.txt <nul set /p unused=%%h)
Upvotes: 4