#67289 - 2002-06-19 10:26 PM
Checking for an existing User Account
|
Anonymous
Anonymous
Unregistered
|
I know there have been a few posts for this situation...was wondering if anyone really found a good solution.
I'm writing a script for a help desk to do our NT Home Directory creation. I've created the script that does all of it including the share/directory rights, but I want the script to check to see if the username entered exists in a specified domain (not the domain that is currently logged into...the help desk is in a different domain). Does anyone know how to do this?
NET USER falls just a wee bit short as it doesn't allow you to specify another domain...it only checks for the domain the user is currently logged into.
Thanks. [ 19 June 2002, 22:27: Message edited by: mmletzko ]
|
|
Top
|
|
|
|
#67290 - 2002-06-19 10:35 PM
Re: Checking for an existing User Account
|
Anonymous
Anonymous
Unregistered
|
Think I just figured it out. I can use the NT Resource Kit command called 'SHOWGRPS'. It actually lets you specify the domain. I can send that to a text file and check for the existence of "Domain Users" or "Everyone". [ 19 June 2002, 22:37: Message edited by: mmletzko ]
|
|
Top
|
|
|
|
#67292 - 2002-06-19 10:54 PM
Re: Checking for an existing User Account
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
There's actually another way to do this:
code:
$domain = "domain" $userid = "administrator" $obj = GetObject("WinNT://$domain/$userid,user") If @error = 0 "Valid User" Else "Not a User on the domain specified" Endif $obj = ""
This assumes you have administrator access to the domain you specify.
Brian
|
|
Top
|
|
|
|
#67294 - 2002-06-19 11:05 PM
Re: Checking for an existing User Account
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
In fact, if you liked that way of doing things, you can use that method to check their home directory as well as other properties:
code:
$obj = GetObject("WinNT://$domain/$userid,user") "User's Home directory is: " $obj.HomeDirectory ? "User's Logon Script is: " $obj.LoginScript ?
Brian
|
|
Top
|
|
|
|
#67295 - 2002-06-19 11:07 PM
Re: Checking for an existing User Account
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
It works fine on my NT domain... as long as you have ADSI installed on the machine you are running a script from. (If it's a 2000 workstation you're fine, too)
Brian
|
|
Top
|
|
|
|
#67297 - 2002-06-19 11:19 PM
Re: Checking for an existing User Account
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Just a hunch.. does $$$$JMSMITH not work?
Brian
|
|
Top
|
|
|
|
#67299 - 2002-06-19 11:32 PM
Re: Checking for an existing User Account
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
To take the time to install ADSI (if it's not already installed) seems to me to be worth it in making the process simpler:
code:
$domain = "domain" $userid = "userid" $fullname = "Last, First" $obj = GetObject("WinNT://$domain/$userid,user") $obj.Put("HomeDirectory","\\server\share") ? $obj.Put("LoginScript","logon.bat") ? $obj.Put("FullName",$fullname) $obj.SetInfo
This simply takes an existing account and modifies the home directory, login script, and name with specified parameters. It isn't that much more of an effort to actually create the account.
Brian
|
|
Top
|
|
|
|
#67303 - 2002-06-20 08:49 AM
Re: Checking for an existing User Account
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
If anyone cares: The error returned by ADSI when the NT account does not exist is -2147022675. To make sense of ADSI errors try this:
1. Convert num to Hex -2147022615 = 0x800708AD 2. Strip top 4 bytes = 08AD 3. Convert back to Dec 0x08AD = 2221 4. Look up this error with NET HELPMSG 2221
code:
H:\temp>net helpmsg 2221
The user name could not be found.
EXPLANATION
You specified an unknown user name.
ACTION
Check the spelling of the user name. To display a list of the users in the security database, type:
NET USER
cj
|
|
Top
|
|
|
|
#67305 - 2002-06-20 02:18 PM
Re: Checking for an existing User Account
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
That's great, cj! I didn't know you could do that. To this point, I was assuming the error number had no relevance.
Brian
|
|
Top
|
|
|
|
#67306 - 2002-06-20 02:57 PM
Re: Checking for an existing User Account
|
Anonymous
Anonymous
Unregistered
|
I just got in this morning and was surprised to see the interest in this! I have not tried Brian's suggestion yet. Don't know much about ADSI (We're still an NT 4 shop as far as domains), and don't have too much time to research. Since the people who will be doing this won't have Domain Admin rights, it may not be what we're looking for (someone mentioned that being an issue?), but I will certainly look into it when the time is right. I think I may try the SHOWGRPS and see how that works. Thanks guys!!
|
|
Top
|
|
|
|
#67307 - 2002-06-23 08:40 AM
Re: Checking for an existing User Account
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
ceej,
That is too good to get swept under the rug.. I think we will incorporate this in the FAQ..
Kent
|
|
Top
|
|
|
|
#67308 - 2002-06-23 02:13 PM
Re: Checking for an existing User Account
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Kent, there is an error in the original post and FAQ. The reported error was -2147022675, but it was mis-typed in the example (-2147022615). Notice the ten's column. The original number is the correct one.
In case anyone is interested in a little automation. This function can be included in your code and called when the COM error <> 0. code:
? ConvertCOMerror(-2147022675)
Function ConvertCOMerror ($error) $error = val("&"+Right(DecToHex($error),4)) ? "Error: $error" shell "net helpmsg $error" Endfunction
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 565 anonymous users online.
|
|
|