From 1b90075d6dbb2b33c593de7ecae4fd2ce2a5af5c Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Thu, 27 Apr 2017 17:27:27 +0300 Subject: [PATCH] getuser may not work in windows --- pupy/modules/users.py | 2 +- pupy/packages/all/pupyutils/users.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pupy/modules/users.py b/pupy/modules/users.py index 54c184af2..7bf5762b5 100644 --- a/pupy/modules/users.py +++ b/pupy/modules/users.py @@ -10,7 +10,7 @@ class Users(PupyModule): """ Get interactive users """ dependencies = { - 'windows': ['win32net'], + 'windows': ['win32net', 'win32api'], 'all': ['pupyutils.users'] } diff --git a/pupy/packages/all/pupyutils/users.py b/pupy/packages/all/pupyutils/users.py index db64b63c5..7d8a1e889 100644 --- a/pupy/packages/all/pupyutils/users.py +++ b/pupy/packages/all/pupyutils/users.py @@ -3,13 +3,12 @@ if os.name == 'nt': import win32net - import socket + import win32api def users(): result = [] - hostname = socket.gethostname() - users, _, _ = win32net.NetUserEnum(hostname, 1) - current = getpass.getuser() + users, _, _ = win32net.NetUserEnum(None, 1) + current = win32api.GetUserName() UF_ACCOUNT_DISABLE = 2 UF_LOCKOUT = 16 @@ -20,7 +19,7 @@ def users(): result.append({ 'name': user['name'], - 'groups': win32net.NetUserGetLocalGroups(hostname, user['name']), + 'groups': win32net.NetUserGetLocalGroups(None, user['name']), 'admin': user['priv'] == 2 })