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 - Check if user defined in SD

Reply
 
Old 09-25-2008   #1 (permalink)
Mad Mark


 
 

Check if user defined in SD

Hi,

How would you check if a specific user given to you exists anywhere in the
domain please?

E.G user id is xxx123456 You want to see if that user is defined or not, if
defined get information. The user may be in a number of unknown and
different OU's.

Many thanks

Mark



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


 
 

Re: Check if user defined in SD

Mark wrote:
Quote:

>
> How would you check if a specific user given to you exists anywhere in the
> domain please?
>
> E.G user id is xxx123456 You want to see if that user is defined or not,
> if defined get information. The user may be in a number of unknown and
> different OU's.
Assuming the user id you have is the "pre-Windows 2000 logon" name, you can
use the NameTranslate object in a VBScript program to convert this (with the
NetBIOS name of the domain) to the Distinguished Name (DN). The DN indicates
where in the hierarchy of AD the object resides. For more on NameTranslate
see this link:

http://www.rlmueller.net/NameTranslateFAQ.htm

The quick example (#6) shows how to do it. If the user does not exist an
error is raised by the Set method. If desired, you could trap this error.
For example:
=============
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify the NetBIOS name of the domain and the NT name of the user.
strNTName = "MyDomain\TestUser"

' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Use the Set method to specify the NT format of the object name.
' Trap error if user does not exist.
On Errro Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNTName
If (Err.Number = 0) Then
On Error GoTo 0

' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)

Wscript.Echo strUserDN
Else
On Error GoTo 0
Wscript.Echo "User " & strNTName & " does not exist"
End If

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


My System SpecsSystem Spec
Old 09-25-2008   #3 (permalink)
Al Dunbar


 
 

Re: Check if user defined in SD


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%231f6x9xHJHA.1308@xxxxxx
Quote:

> Mark wrote:
>
Quote:

>>
>> How would you check if a specific user given to you exists anywhere in
>> the domain please?
>>
>> E.G user id is xxx123456 You want to see if that user is defined or not,
>> if defined get information. The user may be in a number of unknown and
>> different OU's.
>
> Assuming the user id you have is the "pre-Windows 2000 logon" name, you
> can use the NameTranslate object in a VBScript program to convert this
> (with the NetBIOS name of the domain) to the Distinguished Name (DN). The
> DN indicates where in the hierarchy of AD the object resides. For more on
> NameTranslate see this link:
>
> http://www.rlmueller.net/NameTranslateFAQ.htm
>
> The quick example (#6) shows how to do it. If the user does not exist an
> error is raised by the Set method. If desired, you could trap this error.
> For example:
> =============
> ' Constants for the NameTranslate object.
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
> ' Specify the NetBIOS name of the domain and the NT name of the user.
> strNTName = "MyDomain\TestUser"
>
> ' Use the NameTranslate object to convert the NT user name to the
> ' Distinguished Name required for the LDAP provider.
> Set objTrans = CreateObject("NameTranslate")
>
> ' Initialize NameTranslate by locating the Global Catalog.
> objTrans.Init ADS_NAME_INITTYPE_GC, ""
> ' Use the Set method to specify the NT format of the object name.
> ' Trap error if user does not exist.
> On Errro Resume Next
> objTrans.Set ADS_NAME_TYPE_NT4, strNTName
> If (Err.Number = 0) Then
> On Error GoTo 0
>
> ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
> strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
>
> Wscript.Echo strUserDN
> Else
> On Error GoTo 0
> Wscript.Echo "User " & strNTName & " does not exist"
> End If
Or, alternately, you could use a simple batch script with a command such as:

net user /domain xxx123456

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: User defined functions. VB Script
Re: Check if user is already in AD PowerShell
How do I set User Right on Bypass traverse checking to 'Not Defined'? Vista security
User-defined sorting Vista file management


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