469,914 Members | 2,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,914 developers. It's quick & easy.

Try/Except for ADSI GetObject

I am a little confused on why I can not detect an object that does not exist
with a try and except. If I understand ADSI correctly from what I have read
you do not create these objects but rather get them. They already exist. I
believe if I do the equivalent in VB I would generate an error when I try to
get an object that does not exist (can not find). What have I done wrong?
I have included the function below that works in ever respect but detecting
incorrect NT Domain Names (objects that do not exist) . Any tips, insight or
comments would be welcome by this newbie.

Thx
def CheckNT4(header, all):

adsi = win32com.client.Dispatch('ADsNameSpaces')

try:
nt = adsi.GetObject('', "WinNT://"+ frm.NTName) #----->I need some
type of try/except to detect incorrect NT Domain Names
except: print "Domain name failed" # this does not detect a problem

nt.Filter = ['user']
try:
oSID = win32com.client.Dispatch('ADsSid')
except:
MyUsers = [ eauser for eauser in all if eauser[GetPostion(header,
'STATUS')] is '']
for ea in MyUsers:
ea[GetPostion(header, 'STATUS')] = 'FailNT'
ea[GetPostion(header, 'COMMENT')] ='Can not find ADsSid'
MyUsers = [ eauser for eauser in all if eauser[GetPostion(header,
'STATUS')] is '']
intcnt = 0
for user in nt:
for ea in MyUsers:
if string.upper(user.Name) == string.upper(ea[GetPostion(header,
'OLDNTLOGON')]):
frm.MyProgress.Update ( intcnt, 'Found NT user and SID : ' +
user.Name )
intcnt = intcnt+ 1

if user.AccountDisabled:
ea[GetPostion(header, 'STATUS')] = 'FailNT'
ea[GetPostion(header, 'COMMENT')] ='Disabled'
else:
if ea[GetPostion(header, 'COMMENT')] is not '':
ea[GetPostion(header, 'COMMENT')] = ''
oSID.SetAs (5, "WinNT://"+ frm.NTName + '/' + user.Name)
ea[GetPostion(header, 'STATUS')] = 'PassNT'
ea[GetPostion(header, 'Nt4Sid')] = oSID.GetAs(1)

for user in [ eauser for eauser in all if eauser[GetPostion(header,
'STATUS')] is '']:
user[GetPostion(header, 'STATUS')] = 'FailNT'
user[GetPostion(header, 'COMMENT')] = 'NoNt4Account'

May 31 '06 #1
1 2437

"LittlePython" <Li**********@lost.com> wrote in message news:al5fg.9877$ho6.1459@trnddc07...
I am a little confused on why I can not detect an object that does not exist
with a try and except. If I understand ADSI correctly from what I have read
you do not create these objects but rather get them. They already exist. I
believe if I do the equivalent in VB I would generate an error when I try to
get an object that does not exist (can not find).
I don't get an error when doing a GetObject in VBS
for a nonexistent domain.
What have I done wrong? I have included the function below that works in ever respect but detecting
incorrect NT Domain Names (objects that do not exist) . Any tips, insight or
comments would be welcome by this newbie.

You should be able to use win32net.NetValidateName to
verify that the domain exists before doing any more operations.

hth
Roger


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jun 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ondrej Krajicek | last post: by
6 posts views Thread by Miguel Orrego | last post: by
3 posts views Thread by Tom Petersen | last post: by
reply views Thread by Kenneth Keeley | last post: by
reply views Thread by rias | last post: by
14 posts views Thread by Jonathan Smith | last post: by
8 posts views Thread by John | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.