batch file - WMIC commands to change computer name to BIOS serial number -
i'm new batch file , wmic , after researching stackoverflow i've found few answers overlap not producing expected output when put together.
problem:
create batch file change computer name (not on domain):
- use 
wmic bios serialnumber, assign value variablecomp_name, display value of variable; - change computer name value of variable 
comp_name; 
so 1.:
for /f %%f in ('wmic bios serialnumber') ( set comp_name=%%f ) echo %comp_name%   followed 2.:
wmic computersystem name="%computername%" rename name=%%comp_name%%   edit: got 1. part correct - works expected - fetching serial number , displays variable's value. part 2. still throwing errors:
o:\>wmic computersystem name="tom-pc" rename name= invalid named parameter list. hint: <named param list> ::= <named param> | <named param> <named param list> <named param> ::= <param name>=<param value>   if understand correctly - name=... part of last command don't recognise variable initialised above. how use comp_name parameter wmic command?
edit .2
"why using doubled % signs in name=%%comp_name%%?" aschipfl - reverted original question - used double % , getting different error - 87 tells me more problem. using singles % produce error listed above. i'm not sure if problems lies in single or doubles% or somewhere else.
edit .3
further research shows wmic bios serialnumber returns in fact 3 values each in new line 
c:\windows\system32>wmic bios serialnumber serialnumber by3vf02   that - serialnumber string followed actual serial number in new line , last 1 empty line. (i hope) final questions - how assign second value variable please?
give try batch code :
@echo off /f "tokens=2 delims==" %%a in ('wmic bios serialnumber /value') (     /f "delims=" %%b in ("%%a") (         call :renamepc "%%b"          call :ask4reboot     ) ) pause & exit /b ::********************************************************************** :renamepc wmic computersystem name="%computername%" call rename name="%~1" exit /b ::*********************************************************************** :ask4reboot (     echo    set ws = createobject("wscript.shell"^)     echo    answ = msgbox("did want reboot computer ?"_     echo ,vbyesno+vbquestion,"did want reboot computer ?"^)     echo    if answ = vbyes      echo        return = ws.run("cmd /c shutdown -r -t 60 -c ""you need reboot in 1 minute."" -f",0,true^)     echo    else     echo        wscript.quit(1^)     echo    end if )>"%tmp%\%~n0.vbs" start "" "%tmp%\%~n0.vbs"      
Comments
Post a Comment