Changeset 57 for pykoticon

Show
Ignore:
Timestamp:
01/15/05 09:00:04 (20 years ago)
Author:
jerome
Message:

Added a function to retrieve the current user's name under Windows

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykoticon/trunk/bin/pykoticon

    r56 r57  
    2626import urllib 
    2727import urllib2 
     28 
     29try : 
     30    import win32api 
     31    import win32net 
     32    import win32netcon 
     33    hasWindowsExtensions = 1 
     34except ImportError :     
     35    hasWindowsExtensions = 0 
     36     
    2837 
    2938DUMPYKOTA_URL = "http://cgi.librelogiciel.com/cgi-bin/dumpykota.cgi" 
     
    136145        return User(username, info, quotas) 
    137146     
     147def getWindowsUserName() :     
     148    """Retrieves the current user's name under MS Windows.""" 
     149    dc = win32net.NetServerEnum(None, 100, win32netcon.SV_TYPE_DOMAIN_CTRL) 
     150    user = win32api.GetUserName() 
     151    if dc[0] : 
     152        dcname = dc[0][0]['name'] 
     153        return win32net.NetUserGetInfo("\\\\" + dcname, user, 1) 
     154    else: 
     155        return win32net.NetUserGetInfo(None, user, 1) 
     156     
    138157if __name__ == "__main__" : 
    139158    net = CGINetworkInterface(DUMPYKOTA_URL) 
     
    143162     
    144163    #print "User print quotas : ", net.getUserPQuotas("jerome") 
    145     jerome = net.getUser("jerome") 
     164    #jerome = net.getUser("jerome") 
     165    print getWindowsUserName() 
    146166