Batcher
Batcher

Reputation: 5

i want to use command output values to set local admin password via batch file

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

Answers (2)

npocmaka
npocmaka

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

Stephan
Stephan

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 wmics output from Unicode to ANSI.

Upvotes: 1

Related Questions