0

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
Stephan
  • 53,940
  • 10
  • 58
  • 91
Batcher
  • 5
  • 4

2 Answers2

1

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.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Funny note: on my private system, `wmic bios get serialnumber` gives me `to be filled by OEM` – Stephan Jul 03 '17 at 08:25
  • you don't need the `find` - for /f omits the empty lines. – npocmaka Jul 03 '17 at 08:27
  • how to use only last charecters in further use? @ stephan – Batcher Jul 03 '17 at 09:18
  • for example the last four: `set serialnumber=%serialnumber:~-4%`. See `set /?` for details. – Stephan Jul 03 '17 at 09:20
  • It's not `LF` but `CR` that let's lines to appear non-empty; the most robust way to get rid of them is to nest another `for /F` loop, like this: `for /F "skip=1 delims=" %%a in ('wmic BIOS get SerialNumber') do for /F "delims=" %%b in ("%%a") do set %%b` – aschipfl Jul 09 '17 at 12:58
0

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
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • i apply this command in batch file but it does not change password .my pc serial number is SGH552P6JK. – Batcher Jul 03 '17 at 08:35