Page 1 of 2 12>
Topic Options
#67289 - 2002-06-19 10:26 PM Checking for an existing User Account
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
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
#67291 - 2002-06-19 10:48 PM Re: Checking for an existing User Account
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hey, thanks letzko!

i've used net user for a while and this can be really helping!

{edit}
don't know how you do the making of the user and share...
to make these run all once you can skip the rmtshare and others and do it with rmtcmd.
this way also this problem disappears...
just a thougt...
{edit}

cheers,

[ 19 June 2002, 22:51: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#67292 - 2002-06-19 10:54 PM Re: Checking for an existing User Account
BrianTX Offline
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
#67293 - 2002-06-19 11:02 PM Re: Checking for an existing User Account
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it assumes something other too... brian too quick...

if you have pure NT domains, it's better to forget this latter way.
_________________________
!

download KiXnet

Top
#67294 - 2002-06-19 11:05 PM Re: Checking for an existing User Account
BrianTX Offline
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 Offline
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
#67296 - 2002-06-19 11:10 PM Re: Checking for an existing User Account
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Not sure what you mean by PURE NT DOMAIN there Lonkero. Brian's solutions works well. However it does not support the use of other symbols in the name such as $ I thought using $$ might work, but that fails as well.

I have JMSMITH account and $JMSMITH account. This script does not think the $JMSMITH account is valid. I tried adding "$$JMSMITH" but still comes back as invalid.

Top
#67297 - 2002-06-19 11:19 PM Re: Checking for an existing User Account
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Just a hunch.. does $$$$JMSMITH not work?

Brian

Top
#67298 - 2002-06-19 11:22 PM Re: Checking for an existing User Account
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
boys, what I ment was, if he has nt domain, without any specific stuff installed (like adsi) it won't work.
and if he has it installed, he probably would know about it.

anyway when brian stated:
quote:
This assumes you have administrator access to the domain you specify.
he should have stated:
"This assumes you have administrator access to the domain you specify and adsi installed"
_________________________
!

download KiXnet

Top
#67299 - 2002-06-19 11:32 PM Re: Checking for an existing User Account
BrianTX Offline
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
#67300 - 2002-06-20 12:02 AM Re: Checking for an existing User Account
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Lonkero,

mmletzko does not need to have ADSI installed on the PDC/BDC however he does need to run it from a system that does have ADSI installed such as a Windows 2000/XP system. Or as Brian says. Simply install it on his Admin workstation so that he can ease some of the pain of Admin work for himself.

ps. pilot error on my part. I had a typo in my code on the user name. The "$$JMSMITH" does work. I ran it from an NT 4.0 Domain account against an Active Directory account and it came back witht the correct results.

Top
#67301 - 2002-06-20 12:05 AM Re: Checking for an existing User Account
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok. he does not need it in dc but the need of it should have been stated as many ppl does not have it.

{edit}
just to point what i mean you can go to udf-library and check the udf's there.
in those you will see dependencies field.
is there something?
{/edit}

cheers,

[ 20 June 2002, 00:10: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#67302 - 2002-06-20 12:11 AM Re: Checking for an existing User Account
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Is this more of a "pet peeve" or recommendation Lonkero? I don't see where mmletzko wrote back that Brian's code did or did not work.

By now there are hundreds of posts that talk about ADSI. Having to preface every post with the REQUIREMENTS is a little overkill don't you think? If mmletzko wrote back that Brian's code did not work then Brian or others could have pointed out that KiXtart v4.02 and ADSI are requirements, but not in every post one makes in my opinion.

Top
#67303 - 2002-06-20 08:49 AM Re: Checking for an existing User Account
cj Offline
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
#67304 - 2002-06-20 01:46 PM Re: Checking for an existing User Account
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc, point taken.

cj, is this the case with all adsi errors?
_________________________
!

download KiXnet

Top
#67305 - 2002-06-20 02:18 PM Re: Checking for an existing User Account
BrianTX Offline
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
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 Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#67308 - 2002-06-23 02:13 PM Re: Checking for an existing User Account
Howard Bullock Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.074 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org