Sign in to follow this  
Followers 0
byteme

Query To See If Local User Exists

8 posts in this topic

Hi everybody. I was wondering if anybody out there knows of a way that I can check pc's to see if certain local users exist, and if they are locked out or not. I need this because we have multiple pc's that have different admin accounts, and I need to know which one is on the pc so that I can do a runasset. Like I said, I not only need to know if the user exists, but if it is active or locked out. Anybody have any ideas? Thank you in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

you can list the users in the administrators group by doing a "net localgroup administrators"and capture it in a file.

Normally the administrator account doesn't get lockout unless you changed that.

you can also do it this way if you want to try a couple of different userid/password combinations:

AutoItSetOption( "RunErrorsFatal", 0) 
If testUSRPSW("user1" ,"password1") Then
   if testUSRPSW("user2" ,"password2") Then
      If testUSRPSW("user3" ,"password3") Then
         If testUSRPSW("user4" ,"password4") Then
            MsgBox(0,'err','invalid userid/password combo')
         EndIf
      EndIf
   EndIf
EndIf
; run what you want to run here
Exit


Func testUSRPSW($USERNAME,$PASSWORD)
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
  ; Run CMD to test credentials if fails then exits
   RunWait(@ComSpec & " /k exit","",@SW_HIDE) 
   return(@error)
EndFunc  ;==>testUSRPSW
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Good morning JdeB. I was away over the weekend, so this is the first I am seeing this. I appreciate the reply, but have a question about this. Your script has the following lines in it:

If testUSRPSW("user1" ,"password1") Then

if testUSRPSW("user2" ,"password2") Then

If testUSRPSW("user3" ,"password3") Then

If testUSRPSW("user4" ,"password4") Then

MsgBox(0,'err','invalid userid/password combo')

My question is, do I have to put anything at the end of the Then statements? I tried that script, putting in the usernames and passwords I need, and it does the same thing each time, gives me the invalid userid/password combo message box. I tried adding something to the line where you said run what you want here, and it does run it, but not until the invalid message box comes up. Am I missing something here? I am new at this, so if you can, bear with me. Thank you.

Share this post


Link to post
Share on other sites

no problem...

The script does the following:

If testUSRPSW("user1" ,"password1") Then => will perform the testusrpsw function which will return 0 is its a valid userid/password combination and a 1 on invalid combination.

So on an invalid combination the next IF test is performed and when its Valid no other test is done.

Tried it on my WinXP with noexisting and existing user/password combo's and works fine.....

Did you copy the whoile script and update the userdname1-4 and password1-4 to possible existing admin account ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yes, I did put in the correct username accounts, and wrong passwords, and it came up saying that they were all incorrect, which it was supposed to. but then I changed one to have the correct username and password, and it still says incorrect. it never goes to the testusrpsw function test though. It just runs the first few lines, then gives the error. Any idea's as to why it isn't even going to the function test? BTW, I am running Windows 2000 professional, and I am an admin on the pc if that matters. Thanks again!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

it never goes to the testusrpsw function test though.

How did you check this ??

Just put a msgbox in the function to check that... something like:

Func testUSRPSW($USERNAME,$PASSWORD)
  RunAsSet($USERNAME, @ComputerName, $PASSWORD)
; Run CMD to test credentials if fails then exits
  RunWait(@ComSpec & " /k exit","",@SW_HIDE) 
  $err= @error
  msgbox90,'test','error:' & $err)
  return($err)
EndFunc;==>testUSRPSW

EDIT: Just to make sure ... This script is testing for userid's with admin rights! not power or regular user id's..

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

My fault! Sorry! I was putting the message box in the wrong place. I found that it was working after I put it in where you said to put it. I was just expecting to see the dos box when it was doing it's test. Thank you for all of your help. You don't know how much this will help me. Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0