Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - requesting help: Looking to see if a local user exists.

Reply
 
Old 09-17-2008   #1 (permalink)
Ryan


 
 

requesting help: Looking to see if a local user exists.

Im having a bit of trouble finding this. I have some AD samples to do
the same, but I need to find out if a user exists locally.

Basically:
If User "Administrator" exists then call Subexists
else call Subnoexist


figure I would ask.
TYIA

- Ryan


My System SpecsSystem Spec
Old 09-17-2008   #2 (permalink)
Al Dunbar


 
 

Re: requesting help: Looking to see if a local user exists.


"Ryan" <djcalvin@xxxxxx> wrote in message
news:ulUTw0RGJHA.1720@xxxxxx
Quote:

> Im having a bit of trouble finding this. I have some AD samples to do the
> same, but I need to find out if a user exists locally.
>
> Basically:
> If User "Administrator" exists then call Subexists
> else call Subnoexist
>
>
> figure I would ask.
> TYIA
If your "AD samples" use the LDAP provider, this will not work, as local
accounts are, by definition, not AD accounts. You will need to use the WinNT
provider.

/Al


My System SpecsSystem Spec
Old 09-18-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: requesting help: Looking to see if a local user exists.


"Al Dunbar" <AlanDrub@xxxxxx> wrote in message
news:e$4%23GJUGJHA.3736@xxxxxx
Quote:

>
> "Ryan" <djcalvin@xxxxxx> wrote in message
> news:ulUTw0RGJHA.1720@xxxxxx
Quote:

>> Im having a bit of trouble finding this. I have some AD samples to do the
>> same, but I need to find out if a user exists locally.
>>
>> Basically:
>> If User "Administrator" exists then call Subexists
>> else call Subnoexist
>>
>>
>> figure I would ask.
>> TYIA
>
> If your "AD samples" use the LDAP provider, this will not work, as local
> accounts are, by definition, not AD accounts. You will need to use the
> WinNT provider.
>
> /Al
>
>
And one way to tell if a specific user exists is to attempt to bind with the
WinNT provider and trap the possible error. In brief:

strUser = "Administrator"
strComputer = "TestComputer"
On Error Resume Next
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user")
If (Err.Number = 0) Then
On Error GoTo 0
Wscript.Echo "Local user " & strUser & " exists."
Else
On Error GoTo 0
Wscript.Echo "Local user " & strUser & " does NOT exist."
End If

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 09-18-2008   #4 (permalink)
Ryan


 
 

Re: requesting help: Looking to see if a local user exists.

>> Richard Mueller [MVP] wrote
Quote:
Quote:

>>
>>
>
> And one way to tell if a specific user exists is to attempt to bind with the
> WinNT provider and trap the possible error. In brief:
>
> strUser = "Administrator"
> strComputer = "TestComputer"
> On Error Resume Next
> Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user")
> If (Err.Number = 0) Then
> On Error GoTo 0
> Wscript.Echo "Local user " & strUser & " exists."
> Else
> On Error GoTo 0
> Wscript.Echo "Local user " & strUser & " does NOT exist."
> End If
>
That's it.. Thank you VERY much, works perfectly.
I thought there was a userexists call though? (I've been reading way too
many vbs books late late at night, prob misread it)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
renaming Local user account and Changing "Full Name" of same Local VB Script
Ethernet Multiple Networks detected, Local access only, Only one exists Vista networking & sharing
Box requesting user name & password Vista mail
local user PowerShell
local user please PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46