-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminpy.py
34 lines (32 loc) · 1.14 KB
/
adminpy.py
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
"""
\AdminPy/
Open Windows executable in Python!
:copyright: (c) 2016 Fef0
:Thanks to Jorenko from stackoverflow.com for "AsAdmin" function
:Based on Preston Landers "pyuac" work
:license: GNU General Public License v3.0
"""
#WARNING: Requires Windows XP SP2 or higher!
import os
import sys
import win32com.shell.shell as shell
def isUserAdmin():
if os.name == 'nt': # If is running on Windows
import ctypes
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
else:
#Open a Tkinter instance with error if the machine isn't running Windows.
import Tkinter,tkMessageBox
root = Tkinter.Tk()
root.withdraw()
tkMessageBox.showerror('Error!', 'This tool is for Windows only!')
def AsAdmin(arg=None): #Open .exe file
ASADMIN = 'asadmin'
file2open=arg
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
shell.ShellExecuteEx(lpVerb='runas', lpFile=file2open, lpParameters=params)