Reputation: 5
I want to use (wmic bios get serialnumber
) values to set local admin password in Windows 7.
I wrote a small script which has some bugs. Please help to fix it.
@ECHO OFF
set a=wmic bios get serialnumber
net user administrator 123-%a%
pause
Upvotes: 0
Views: 398
Reputation: 57282
This can be considered as duplicate of this. But wmic commands could need additional for loop for better parsing:
@ECHO OFF
for /f "tokens=* delims=" %%a in ('wmic bios get serialnumber /format:value') do (
for /f "tokens=* delims=" %%# in ("%%a") do set "%%#"
)
net user administrator 123-%SerialNumber%
pause
Upvotes: 0
Reputation: 56208
the usual way to get a commands output is a for /f
loop:
for /f "delims=" %%a in ('wmic bios get serialnumber /value ^|find "="') do set %%a
echo %serialnumber%
The find
is used to a) get the correct line and b) convert wmic
s output from Unicode to ANSI.
Upvotes: 1