473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2576

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ondrej Krajicek | last post by:
Hello, I have problem with the following code: rootdse = ldap.OpenDSObject(ROOTDSE_URL, USER_NAME, PASSWORD, opts) nc = rootdse.Get("defaultNamingContext") uri = "LDAP://%s/%s" %...
6
by: Miguel Orrego | last post by:
Hi, I have found some code that authenticates users agains a domain using ADSI. I then redirect to another page and pass the username they have entered as a string. However, it would be nice to...
0
by: Srinivas | last post by:
Hi, I've one system in which Active directory is installed. That system is the domain controller as well as web server - A test machine. Trying all following to Authenticate Users using VB as...
3
by: Tom Petersen | last post by:
My users logon to the Patriot domain, my intranet is on sdsddata01 server. I have a form that people have to click on a dropdown list to pick their name from the list when submitting a form. Is...
0
by: Kenneth Keeley | last post by:
Hi, Under ASP I was able to use code like that listed below to confirm login details on our intranet site. I wish to upgrade our site to run purely under ASP.NET. I am having trouble converting...
0
by: rias | last post by:
I'm new to VB.NET and ADSI. By default it appears the adsi limits objects returned to 1000 items. I've seen web references that say that the limit is imposed by unpaged queries. I added an...
1
by: andy | last post by:
Has anyone ever experienced any problems authenticating with an ADSI application where after so long it stops responding. I can not track down what is causing the problem. I have a login page that...
14
by: Jonathan Smith | last post by:
I am trying to develop an app using ADSI. I have the following code: Dim ADSUser As IADsUser ADSUser = GetObject("LDAP://CN=jonsmith,CN=users,DC=domain,DC=com") ...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.