AnsweredAssumed Answered

arcpy.ListUsers()

Question asked by jborgion Champion on Jun 22, 2018
Latest reply on Aug 19, 2018 by Dan_Patterson

Using ListUsers—Help | ArcGIS Desktop  as my reference I'm trying to get a list of users connected to an eGDB that I can iterate through.

 

The online help page suggests:

# Set the admistrative workspace connection
arcpy.env.workspace = "Database Connections/tenone@sde.sde"

# Create a list of users
'''
NOTE: When the arcpy.env.workspace environment is set, a workspace
does not need to be provided to the function.
'''

users = arcpy.ListUsers()

 However, my attempt errors out:

 

>>> arcpy.env.workspace = r'I:\PathTo\SdeUserConnection\sde@My.sde'
>>> users = arcpy.ListUsers()
Runtime error
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: ListUsers() takes exactly 1 argument (0 given)

  

If I specify the workspace  and output it to a variable name, I get a list of tuples, which is cool, but then I have to step through it and tease out what I want:

 

ws = arcpy.env.workspace  #set in line 1 above...
users = arcpy.ListUsers(ws)
>>> users
[user(ClientName=u'ad-trasmussen:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 1, 14), ID=388635, IsDirectConnection=True, Name=u'"SLCOUNTY\\TARASMUSSEN"'), user(ClientName=u'AD-TBAIN-10:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 6, 13), ID=388636, IsDirectConnection=True, Name=u'"SLCOUNTY\\TBAIN"'), user(ClientName=u'ad-trasmussen:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 11, 12), ID=388637, IsDirectConnection=True, Name=u'"SLCOUNTY\\TARASMUSSEN"'), user(ClientName=u'AD-TBAIN-10:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 11, 32), ID=388638, IsDirectConnection=True, Name=u'"SLCOUNTY\\TBAIN"'), user(ClientName=u'AD-BLECHEMINANT:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 10, 39, 34, 1), ID=388640, IsDirectConnection=True, Name=u'"SLCOUNTY\\BLECHEMINANT"'), user(ClientName=u'is-jborgione-10:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 11, 30, 20), ID=388641, IsDirectConnection=True, Name=u'SDE')]

for i in range(len(users)):
...     print users[i][4]

#prints the user name

 

But I'd rather not do that if I don't have to: I'd much rather use the list object/methods to step through so I can  get user.name or user.ID

 

What's the secret to get arcpy.ListUsers() to work as advertised? 

Outcomes