Solved I want to run WMIC in batch, but to allow to enter variable

November 15, 2012 at 10:38:59
Specs: Windows XP

I'm using the WMIC cmd to rename a local user in WinXP. I want to create a batch to run the below cmd line, but allow to enter variable of newusername.

wmic useraccount where name='user'call rename name='newusername'


See More: I want to run WMIC in batch, but to allow to enter variable

Report •


✔ Best Answer
November 15, 2012 at 17:25:07

yeh, I just used your exact syntax, and we're both running xp, and mine worked.
i did notice this however:
wmic useraccount where name='user'call rename name='newusername'

having no space between 'user' and call, generated "invalid inquiry".
try this:
wmic useraccount where name='%1' call rename name='%2'

(apologies for my former post: i cut/pasted your code, hence it still contained the error of no space).



#1
November 15, 2012 at 12:13:36

wmic useraccount where name='%1'call rename name='%2'

or if you want prompts:
@echo off & setlocal
set /p user=currentusername:
set /p newusername=new username:
wmic useraccount where name='%user%'call rename name='%newusername%'


Report •

#2
November 15, 2012 at 12:23:55

Thank you for your prompt reply; but I have tried this before in several different ways and got the below error:

ERROR:
Code = 0x80041017
description = Invalid query
Facility = WMI

I thought that it might be a syntax issue, but I'm not sure.


Report •

#3
November 15, 2012 at 12:42:22

I assume that you have already ensured that everything is working before running the script. if not you might consider running this to check:

http://www.microsoft.com/downloads/...

Just in case its not the coding.

:: mike


Report •

Related Solutions

#4
November 15, 2012 at 17:25:07
✔ Best Answer

yeh, I just used your exact syntax, and we're both running xp, and mine worked.
i did notice this however:
wmic useraccount where name='user'call rename name='newusername'

having no space between 'user' and call, generated "invalid inquiry".
try this:
wmic useraccount where name='%1' call rename name='%2'

(apologies for my former post: i cut/pasted your code, hence it still contained the error of no space).


Report •


Ask Question