简体   繁体   中英

How to Check if an user account exists or not (on local machine) in windows?

I am trying to verify whether a particular user exists on the local computer. The one solution that I can do is parsing the output of command Net user . But is there any better solution than this?

You can possibly use WMI with a query such as "select * from Win32_UserAccount where LocalAccount = True" or similar. If you are just looking for a specific account you can be able to restrict the WMI query more. See Win32_UserAccount . You may also just be able to use GetObject (which may be more efficient), but I don't know how to formulate that.

You can follow the template/code at http://snippets.dzone.com/posts/show/6967 (which is not relating to user accounts :-) to setup/create the WMI ActiveX object, execute the query, and enumerate the results.

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM