Home > Uncategorized > WQL/WMI query to check if a user exists

WQL/WMI query to check if a user exists

For some odd reason, MSFT didn’t code a straight item-level targeting rule to allow you to query local users. So, if you are renaming a local user, and it is already in existence (which it will be after you rename it), your client will log an error.

In order to avoid the error, you must check if the user exists using the following WQL:

select * from win32_useraccount where localaccount = 1 and caption like '%Administrator'
select * from win32_useraccount where localaccount = 1 and caption like '%Guest'

Note that the caption property will return the computer name as the realm of the user followed by the user (like COMPUTER\Administrator); this is why it checks with a wildcard.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: