Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 4

Problem with using wmic commands in a batch file

Hey, I am trying to check if user exists on a Windows system by running the following command using the "Execute script/batch file" option

wmic useraccount get /format:value | findstr $USER$

however that command just hangs indefinitely and the install freezes. If I change it to

wmic "useraccount get /format:value | findstr $USER$"

It still hangs. If I change it to

"wmic useraccount get /format:value | findstr $USER$"

It does not hang but I get the error "The System cannot find the path specified".

Is there some way you need to use wmic to get it to work or is there another way to check that a user exists in a Windows system?

Thanks for the help,
Labels (1)
0 Kudos
(6) Replies
Level 9


The following command works:
wmic useraccount get /format:value | findstr "$USER$"

this is like your hanging command but prevents error in case of space in $USER$ name.

Anyway this command (in execute script) works, I guess it does not hang for you but only takes a long time answering ...

You can try by using execute script with wmic /? for example and checking the result of $EXECUTE_STDOUT$.
0 Kudos
Level 4

Well I'm not sure how long is long, but I just let it go for a full hour and it still was hanging. If nothing else that is far to long to go into a customer product.

When I did wmic /? it still hung forever. This is what my exact window looks like:

Am I doing something wrong since you said this is supposed to work?
0 Kudos
Level 20

Well, there is no reason for which the wmic should hang... most likely there's some kind of issue when called from within IA. Personally, I don't like the Execute Batch/Script, and I tend to replace it with Execute Command. I would try to execute the following command:

$SYSTEM_32$$/$Wbem$/$wmic.exe useraccount get /format:value | $SYSTEM_32$$/$findstr.exe "$USER$"

If this doesn't work then please try execute the following:

CMD /C $SYSTEM_32$$/$Wbem$/$wmic.exe useraccount get /format:value | $SYSTEM_32$$/$findstr.exe "$USER$"

And if this doesn't work either then I would recommend that in your installer you create a .bat file that you would install and call by using Execute Target. That should do the trick.
0 Kudos
Level 4

Thanks for those suggestions, but unfortunately none of them worked and they all hung indefinitely as well.

My batch file looked like this

@echo off
wmic useraccount get /format:value | findstr drew
dir c:\windows

The batch file ran correctly when I just ran it by itself standalone.

With all of these different solutions causing the same problem I'm beginning to think it might be a system error. I'm on Windows XP SP2. Could this be an issue with that and not an IA bug? Perhaps a permission issue?
0 Kudos
Level 20

Well, if you do put a pause in your .bat file I guess that the installer will wait indefinitely for you to press a key... but you no longer have the input to the bat when launched from within IA.
0 Kudos
Level 2

I know this will sound crazy, but i was having intermittent problem with this when using batch scripts before just typing it from command line.

I found if i redirected input from nul it would operate normally again.. e.g.

wmic process get
0 Kudos