This repository was archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusernameselect.py
More file actions
100 lines (82 loc) · 3.82 KB
/
usernameselect.py
File metadata and controls
100 lines (82 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -----------------------------------------------------------------------------
# Copyright (c) 2019 Brennan Goewert
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
from tkinter import *
import subprocess
import logging
class UsernameSelect():
def __init__(self, master, output_var, remote_host=None):
logging.info('Initializing UsernameSelect...')
self.username = str()
self.remote_host = remote_host
self.results = None
self.get_users(master, output_var, remote_host)
def get_users(self, master, output_var, host=None):
self.dia_list = Toplevel(master)
self.dia_list.title('Select a username from the computer')
self.dia_list.geometry('200x600')
self.dia_list.resizable(True, True)
self.dia_list.grid_columnconfigure(0, weight=1)
self.dia_list.grid_rowconfigure(0, weight=1)
self.dia_list.focus()
self.list_usernames = Listbox(self.dia_list, selectmode=SINGLE)
logging.info('Showing user selection prompt!')
if host:
logging.info('Showing users from "' + host + '"...')
self.results = subprocess.run(
['wmic', '/node:{}'.format(host),
'UserAccount', 'get', 'Name'],
stdout=subprocess.PIPE).stdout.decode('utf-8').split()
results = self.results
for result in results:
logging.info('Found "' + str(result) + '" user on "' +
str(host) + '" !')
results.sort()
return results
else:
logging.info('Showing local users')
self.results = subprocess.run(
['wmic', 'UserAccount', 'get', 'Name'],
stdout=subprocess.PIPE).stdout.decode('utf-8').split()
results = self.results
for result in results:
logging.info('Found "' + str(result) + '" user!')
results.sort()
return results
for r in results:
if r in ['Name',
'Administrator',
'DefaultAccount',
'Guest',
'WDAGUtilityAccount']:
continue
self.list_usernames.insert(END, r)
self.list_usernames.grid(row=0, column=0, pady=(10, 10), sticky='nswe')
self.list_usernames.selection_set(first=0)
self.list_usernames.bind(
'<Double-Button-1>', lambda e: output_var.set(self.get(e)))
def get(self, event):
w = event.widget
index = int(w.curselection()[0])
value = w.get(index)
w.destroy()
# return w.selection_set(0)
self.username = value
self.dia_list.destroy()
logging.info('Selected "' + value + '"!')
return value